一、问题背景
在Docker中通过systemctl 启动服务的时候,总是报“Failed to get D-Bus connection: Operation not permitted ”这样的错误提示,如下所示:
[root@localhost ~]# systemctl start sshd
Failed to get D-Bus connection: Operation not permitted
为了解决在Docker运行的镜像中启动服务时报出以上错误信息,整理了一下解决办法,解决方法如下:
二、解决办法
在docker run 启动container的时候,加上/usr/sbin/init ,这样运行起来的container就可以使用systemctl来启动服务了,如下所示:
[root@localhost ~]# docker run -tid --name nginx centos/nginx:v01 /usr/sbin/init
另一种解决办法,就是在通过Dockerfile生成镜像文件的时候,通过CMD来执行/usr/sbin/init这条命令,即:CMD [ "/usr/sbin/init"]。
如果你想了解更多内容,欢迎访问我的CSDN博客:blog.csdn.net/myself88129 这里分享了许多技术文章和心得,让我们一起学习,共同进步。期待你的到来!