zl程序教程

您现在的位置是:首页 >  Java

当前栏目

Failed to get D-Bus connection: Operation not permitted

2023-02-18 16:47:45 时间

docker中使用命令systemctl 命令时会报错,错误信息:

Failed to get D-Bus connection: Operation not permitted。

原因:在centos7的docker容器里面不能用service启动服务。

报这个错的原因是dbus-daemon没能启动。systemctl并不是不能使用。将CMD或者entrypoint设置为/usr/sbin/init即可。docker容器会自动将dbus等服务启动起来。 查看自己的镜像文件:

 docker images
 
 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
 centos              centos7             5e35e350aded        5 months ago        203MB

之前启动容器的命令是:

docker run -itd --name centos-test centos:centos7

我们重新启动一个容器centos-test2 ,不想改名字也可以将centos-test 容器停止删除。 然后我们使用命令:

docker run -itd --name centos-test2 --privileged=true centos:centos7 /usr/sbin/init

然后我们进入容器:

 docker exec -it centos-test2 /bin/bash

就可以使用 systemctl 命令了。