Operation not allowed by systemctl with docker + systemctl

Dockerfile

FROM centos:7 ENV container docker VOLUME ["/sys/fs/cgroup"] RUN yum -y update RUN yum install -y httpd RUN systemctl start httpd.service ADD . /code WORKDIR /code 

Docker-compose.yml

 version: '2' services: web: privileged: true build: . ports: - "80:80" volumes: - .:/code 

Command

 docker-compose build 

Error

Step 6: run the systemctl run httpd.service ---> Run in 5989c6576ac9? [91mFailed for D-Bus connection: operation not allowed? [0m? [31mERROR? [0m: Service 'web' could not be created: the command '/ bin / sh -c syste mctl start httpd.service' returns a non-zero code: 1

Review : works on windows 7: (

What advice?

+6
source share
2 answers

As explained in the image repository of the centos dock , Systemd is not active by default. To use systemd, you will need to include text similar to the Dockerfile example below:

 FROM centos:7 MAINTAINER "you" < your@email.here > ENV container docker RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ rm -f /lib/systemd/system/multi-user.target.wants/*;\ rm -f /etc/systemd/system/*.wants/*;\ rm -f /lib/systemd/system/local-fs.target.wants/*; \ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ rm -f /lib/systemd/system/basic.target.wants/*;\ rm -f /lib/systemd/system/anaconda.target.wants/*; VOLUME [ "/sys/fs/cgroup" ] CMD ["/usr/sbin/init"] 

This Docker file deletes several block files that may cause problems. From here you can create a base image.

 $ docker build --rm -t local/c7-systemd . 

To use the base container with systemd support created above, you will need to change the Docker file to:

 FROM local/c7-systemd ENV container docker VOLUME ["/sys/fs/cgroup"] RUN yum -y update RUN yum install -y httpd RUN systemctl start httpd.service ADD . /code WORKDIR /code 
+3
source

For the same problem, I created docker-systemctl-replacement that will follow the steps that will be followed by the systemctl start httpd.service ... command, but without the need to use SystemD. Just say "systemctl.py start httpd.service" and see if this works.

+1
source

All Articles