在centos7的docker容器里面不能用service启动服务。
systemctl start sshd
报错内容:Failed to get D-Bus connection: Operation not permitted。
报这个错的原因是dbus-daemon没能启动。systemctl并不是不能使用。将CMD或者entrypoint设置为/usr/sbin/init即可。docker容器会自动将dbus等服务启动起来。如下:
docker run --privileged -ti --name test1 centos /usr/sbin/init
需要注意的是,docker 容器运行Ubuntu遇到类似的问题时:
System has not been booted with systemd as init system (PID 1). Can't operate.
/usr/sbin与/sbin并不是链接关系,在/usr/sbin下没有init的
docker run --privileged -ti --name test1 ubuntu /sbin/init
不想每次为了开启一个容器都要打开一个power shell,那么就用 ctrl +q +p来退出容器终端吧。
转载自:https://blog.csdn.net/shenzhen_zsw/article/details/73928195