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

释放双眼,带上耳机,听听看~!

docker版本:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1[root@localhost gae_proxy]# docker version
2Client:
3 Version:         1.10.3
4 API version:     1.22
5 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64
6 Go version:      go1.6.3
7 Git commit:      d381c64-unsupported
8 Built:           Thu Aug  4 13:21:17 2016
9 OS/Arch:         linux/amd64
10
11Server:
12 Version:         1.10.3
13 API version:     1.22
14 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64
15 Go version:      go1.6.3
16 Git commit:      d381c64-unsupported
17 Built:           Thu Aug  4 13:21:17 2016
18 OS/Arch:         linux/amd64
19

镜像版本


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

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

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

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

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

1
2
3
4
1    这样运行起来的container就可以使用systemctl来启动服务了,有的人说在CentOS7.2中解决了通过systemctl运行报错的问题,但是我在实际操作中还是遇到这样的问题。
2    还有一种解决办法,就是在通过Dockerfile生成镜像文件的时候,通过CMD来执行/usr/sbin/init这条命令,即:CMD [ "/usr/sbin/init"];
3
4

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

给TA打赏
共{{data.count}}人
人已打赏
安全运维

MongoDB数据建模小案例:多列数据结构

2021-12-11 11:36:11

安全运维

Ubuntu上NFS的安装配置

2021-12-19 17:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索