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

镜像版本

[root@b2ca5610d3da /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 
  • 1
  • 2
    在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
  • 1
  • 2
    解决办法就是在docker run 的时候运行/usr/sbin/init 。比如:
  • 1
  • 2
[root@localhost /]# docker run -tid --name hadoopbase centos/hadoopbase:v001 /usr/sbin/init
  • 1
    这样运行起来的container就可以使用systemctl来启动服务了,有的人说在CentOS7.2中解决了通过systemctl运行报错的问题,但是我在实际操作中还是遇到这样的问题。
    还有一种解决办法,就是在通过Dockerfile生成镜像文件的时候,通过CMD来执行/usr/sbin/init这条命令,即:CMD [ "/usr/sbin/init"];
  • 1
  • 2
  • 3

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值