Friends who have just contacted docker may encounter such a problem. After creating a container with centos7 image, they use systemctl to start the service and report an error. For this error report, we will analyze it 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
Can’t start the service, what’s the situation
Can’t the container run the service
A:
The design concept of docker is that there is no background service running 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 the service in the container. The life cycle of a container exists around the main process, so the correct way to use the container is to run the service in the foreground
As for SYSTEMd, this suite has become the default service management of mainstream Linux distributions (such as centos7 and Ubuntu 14 +), replacing the traditional system V style service management. SYSTEMd maintains system services, which require privileges to access the Linux kernel. And the container is not a complete operating system, only a file system, and the default boot is only ordinary users such permissions to access the Linux kernel, that is, there is no privilege, so naturally it can not be used
Therefore, please follow the container design principles, a container to run a front desk service
I just want to run like this, can’t I solve it
A: Yes, run the container in privileged mode
Create container:
docker run -d –name centos7 –privileged=true centos:7 /usr/sbin/init
Enter the container:
docker exec -it centos7 /bin/bash
In this way, you can use systemctl to start the service