linux docker Error Failed to get D-Bus connection: Operation not permitted

creates the container with the centos7 image, inside which the systemctl startup service reports an error. For this error, we will analyze next!

# docker run -itd --name centos7 centos:7
# docker attach centos7
# yum install vsftpd
# systemctl start vsftpd
Failed to get D-Bus connection: Operation not permitted

cannot start the service, what happens?

can’t the container run the service!!

a:

Docker’s design concept is not to run background services in the container. The container itself is an independent main process on the host, which can also be indirectly understood as the application process running services in the container. The life cycle of a container revolves around the main process, so the correct way to use the container is to run the services inside in the foreground.

speaking of systemd, this suite has become the default service management for major Linux distributions (such as CentOS7, Ubuntu14+), replacing the traditional systemv-style service management. Systemd maintains the system server program, which requires privileges to access the Linux kernel. And the container is not a complete operating system, only a file system, and default boot is only ordinary users such permissions to access the Linux kernel, that is, no privileges, so naturally not use!

therefore, follow the container design principles and run a foreground service in a container!

, that’s how I want to run it, can’t I solve it?

answer: yes, run the container in privileged mode.

create container:

# docker run -d --name centos7 --privileged=true centos:7 /usr/sbin/init

into the container:

# docker exec -it centos7 /bin/bash

so you can start the service using systemctl.

Read More: