CentOS / sig-cloud-instance-images

CentOS cloud images
777 stars 559 forks source link

Failed to get D-Bus connection: Operation not permitted #45

Open Treverix opened 8 years ago

Treverix commented 8 years ago

When trying to build an image based on this Dockerfile:

FROM centos:latest
MAINTAINER andreas.dolk@mpi.lu

# systemd (Source: https://github.com/docker-library/docs/tree/master/centos#systemd-integration)
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"]

# Apache
RUN yum install -y httpd httpd-devel
RUN chkconfig httpd on
RUN apachectl start

the last step fails:

Step 9 : RUN apachectl start
 ---> Running in 70e7de9def6a
Failed to get D-Bus connection: Operation not permitted
The command '/bin/sh -c apachectl start' returned a non-zero code: 1

The lines below the systemd comment have been copied from the docs today (see reference in the comment)

rickalm commented 8 years ago

I ran across this when trying to solve a similar DBUS problem

https://github.com/CentOS/sig-cloud-instance-images/issues/41

Hope it helps

xichengc commented 7 years ago

@Treverix I am having the same problem. Have you solved this? Thanks.

jamshid commented 7 years ago

Not sure but most instructions about centos and systemd in docker out outdated. See this for current working instructions: https://github.com/docker/docker/issues/28614#issuecomment-261724902

I don't think you can run services via systemd in a docker build. Special privileges are needed. You can only enable / disable services, e.g.: RUN systemctl enable dnsmasq

If you need to run apache during the build maybe you could instead run it in foreground: RUN apachectl -D FOREGROUND & sleep 30 && curl -i localhost

If you need your container startup CMD to run a bash script before starting systemd init (e.g. to do some configuration based on env variables), that works if the script ends by calling exec /usr/sbin/init.

tmarshall commented 7 years ago

I'm having the same problem, on OSX 10.11.6 (El Capitan). Docker version 1.11.1, build 5604cbe.

My app is trying to start up Postgres 9.5.

Running:

docker run -i -t \
  --privileged \
  -p 80:3000 \
  --cap-add SYS_ADMIN \
  -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
  --dns 4.4.4.4 --dns 8.8.4.4 \
  -e NODE_ENV="${NODE_ENV}" \
  tmarshall/latest bash;

My Dockerfile builds off of the same given in https://hub.docker.com/_/centos/ (see "Dockerfile for systemd base image").

There was also an older thread that mentioned a fix for Ubuntu users, which I tried to apply to OSX, via -v $(mktemp):/run but that did not help.

No matter what, I always get

Redirecting to /bin/systemctl start  postgresql-9.5.service
Failed to get D-Bus connection: Operation not permitted
tmarshall commented 7 years ago

^ I got it to work by referring to @zokeber's repo, docker-postgresql

tuanpht commented 6 years ago

I can run systemd in Centos 7 with this command:

docker run --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro -d centos:7 /sbin/init

More references:

kuncao commented 6 years ago

please refer https://github.com/docker-library/docs/issues/1177