Centos7 docker容器报 docker Failed to get D-Bus connection 错误(新增Ubuntu的类似问题解决方案)

在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

发布了55 篇原创文章 · 获赞 29 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/ruibin_cao/article/details/96977210
今日推荐