起因是这样:我当前已进入Docker容器里面,在容器的操作系统(centos7)使用systemctl命令的时候,出错了,错误信息:System has not been booted with systemd as init system (PID 1). Can't operate.
如:systemctl status keepalived
问题原因:
我启动centos容器的命令是:
docker run -itd --name centos_java_nginx hejianliang/centos:java_nginx /bin/bash
需要改为:
docker run -itd --name centos_java_nginx --privileged=true hejianliang/centos:java_nginx /sbin/init
在原命令上加了 --privileged=true,修改/binbash 为 /sbin/init (重点)
修改过后,重新运行就可以在容器里正常使用systemctl命令了