服务器之家:专注于服务器技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - 服务器知识 - 详解docker中使用systemctl启动服务报错的解决办法

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

2021-03-31 16:36rznice 服务器知识

这篇文章主要介绍了详解docker中使用systemctl启动服务报错的解决办法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

docker版本:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[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

镜像版本

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

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

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

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

?
1
[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

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

原文链接:https://blog.csdn.net/rznice/article/details/52253114

延伸 · 阅读

精彩推荐