8

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 systemctl start httpd.service ---> Running in 5989c6576ac9 ?[91mFailed to get D-Bus connection: Operation not permitted ?[0m?[31mERROR?[0m: Service 'web' failed to build: The command '/bin/sh -c syste mctl start httpd.service' returned a non-zero code: 1

Obs: running on a windows 7 :(

Any tip?

JoeLoco
  • 2,116
  • 4
  • 31
  • 59

2 Answers2

4

As explained in centos docker image repository, Systemd is not active by default. In order to use systemd, you will need to include text similar to the example Dockerfile 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 Dockerfile deletes a number of unit files which might cause issues. From here, you are ready to build your base image.

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

In order to use the systemd enabled base container created above, you will need to change your Dockerfile 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
NetworkMeister
  • 1,625
  • 2
  • 14
  • 19
  • This didn't work for me, I still get th same operation not permitted error right when building the docker image – B T Dec 29 '16 at 02:20
1

For the same issue I have created a docker-systemctl-replacement which will do the steps that "systemctl start httpd.service" would do... but without the need of a running SystemD. Just say "systemctl.py start httpd.service" and see if that works.

Guido U. Draheim
  • 3,038
  • 1
  • 20
  • 19