当前位置: 首页 > 新闻动态 > 软件编程

详解docker中使用systemctl启动服务报错的解决办法

作者:用户投稿 浏览: 发布日期:2026-01-11
[导读]:这篇文章主要介绍了详解docker中使用systemctl启动服务报错的解决办法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

docker版本:

[root@localhost gae_proxy]# docker version
Client:
 Version:     1.10.3
 API version:   1.22
 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64
 Go version:   go1.6.3
 Git commit:   d381c64-unsupported
 Built:      Thu Aug 4 13:21:17 2016
 OS/Arch:     linux/amd64

Server:
 Version:     1.10.3
 API version:   1.22
 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64
 Go version:   go1.6.3
 Git commit:   d381c64-unsupported
 Built:      Thu Aug 4 13:21:17 2016
 OS/Arch:     linux/amd64

镜像版本

[root@b2ca5610d3da /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 

在docker中通过systemctl 启动服务的时候总是报Failed to get D-Bus connection: Operation not permitted 这样的错误提示。

[root@25d27693a24d ~]# systemctl start sshd
Failed to get D-Bus connection: Operation not permitted

解决办法就是在docker run 的时候运行/usr/sbin/init 。比如:

[root@localhost /]# docker run -tid --name hadoopbase centos/hadoopbase:v001 /usr/sbin/init

这样运行起来的container就可以使用systemctl来启动服务了,有的人说在CentOS7.2中解决了通过systemctl运行报错的问题,但是我在实际操作中还是遇到这样的问题。

还有一种解决办法,就是在通过Dockerfile生成镜像文件的时候,通过CMD来执行/usr/sbin/init这条命令,即:CMD [ "/usr/sbin/init"];

参考:https://github.com/docker/docker/issues/7459
          https://github.com/docker/docker/issues/2296

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

免责声明:转载请注明出处:http://sczxchw.cn/news/452235.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!