Failed to get D-Bus connection: Operation not permitted centos7 docker runc

最近遇到了一个问题,在centos7的容器中service启动服务会报错Failed to get D-Bus connection: Operation not permitted

[root@ng8w7c7 /]# service ng8w status
Redirecting to /bin/systemctl status ng8w.service
Failed to get D-Bus connection: Operation not permitted

网上查询一个一番,有这样集中解释和解决方式:

一。以特权模式运行容器

    Docker的设计理念是在容器里面不运行后台服务,容器本身就是宿主机上的一个独立的主进程,也可以间接的理解为就是容器里运行服务的应用进程。一个容器的生命周期是围绕这个主进程存在的,所以正确的使用容器方法是将里面的服务运行在前台。

再说到systemd,这个套件已经成为主流Linux发行版(比如CentOS7、Ubuntu14+)默认的服务管理,取代了传统的SystemV风格服务管理。systemd维护系统服务程序,它需要特权去会访问Linux内核。而容器并不是一个完整的操作系统,只有一个文件系统,而且默认启动只是普通用户这样的权限访问Linux内核,也就是没有特权,所以自然就用不了。

解决方式:在创建容器的时候加上--privileged选项。(亲测没什么用处。。。)

二。rpm -ql

还有一种说法就是rpm -ql 软件包,用这种方式查看安装的时候有哪些命令在PATH下,用这些命令启动。这种方式我没有测试,觉得太麻烦了。

三。entrypoint设置为/usr/sbin/init

还有人说这个问题的原因是因为dbus-daemon没能启动,但是systemctl并不是不能用。把entrypoint设置为/usr/sbin/init即可,这样会自动将dbus服务启动起来。(靠谱,我就是用这个方式,亲测有效)

[root@ng8w7c7 /]# systemctl list-unit-files
UNIT FILE                              STATE   
proc-sys-fs-binfmt_misc.automount      static  
dev-hugepages.mount                    static  
dev-mqueue.mount                       static  
proc-fs-nfsd.mount                     static  
proc-sys-fs-binfmt_misc.mount          static  
sys-fs-fuse-connections.mount          static  
sys-kernel-config.mount                static  
sys-kernel-debug.mount                 static  
tmp.mount                              disabled
var-lib-nfs-rpc_pipefs.mount           static  
brandbot.path                          disabled
systemd-ask-password-console.path      static  
systemd-ask-password-wall.path         static  
acpid.service                          enabled

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值