Start a service in docker container failed,with error: Failed to get D-Bus connection: No connection to service manager

baoxinru picture baoxinru · Feb 13, 2015 · Viewed 11.6k times · Source

I installed docker image and built a image successfully.

When I ssh to the container and run the command service xxx start, an error popped:

service nginfra start

Redirecting to /bin/systemctl start nginfra.service /sbin/service: line 79: /bin/systemctl: No such file or directory

Actually, fakesystemd is installed in the container instead of systemd.

So I removed fakesystemd and installed systemd with the command: yum swap -- remove fakesystemd -- install systemd systemd-libs

But I still can't start the service:

service nginfra start

Redirecting to /bin/systemctl start nginfra.service Failed to get D-Bus connection: No connection to service manager.

Does anyone ever meet and solved this issue?

Answer

ocean picture ocean · Sep 18, 2015

This is known issue with systemd-based OSes inside Docker containers.

Short answer: as well as replacing fakesystemd with systemd you need to attach /sys/fs/cgroup as a read-only volume into the container, build the image and then run it in "privileged" mode.

This is the best guide I've found for this. It uses Centos as the example, but should work with any systemd-based OS.