How To Running Systemd on openSUSE Docker Container

After had some headache because of learning for a logic gate :D. I tried again to solving old case why openSUSE container on docker can’t running systemd.

So, I have run openSUSE container on docker. But when I start the container, systemd can’t be running because of this error.

Failed to connect to bus: No such file or directory.

I have tried many ways to solve it, but it still can’t after i found a miracle :D. Thank you, reszelas!

Obviously, the problem is simple. Normally when you run a container you aren’t running an init system. systemctl is a process that communicates with systemd over dbus. If you aren’t running dbus or systemd, I would expect systemctl to fail. So, in openSUSE container, dbus and sysvinit are not installed.

You need to install that dependency and run some command to running systemctl on your container. For easy ways, you can build it using Dockerfile and use official images.

Below is following step to enable systemd on your openSUSE Docker Container :

  • Build a container using Dockerfile, copy following content for your Dockerfile:
FROM opensuse:latest
MAINTAINER Some people 

RUN zypper install -y dbus-1 systemd-sysvinit
RUN cp /usr/lib/systemd/system/dbus.service /etc/systemd/system/; \
    sed -i 's/OOMScoreAdjust=-900//' /etc/systemd/system/dbus.service

VOLUME ["/sys/fs/cgroup", "/run"]

CMD ["/sbin/init"]

Then, build it :

docker build -t opensuse423 .

Run the container:

docker run -d --name=opensuse-systemd -v /sys/fs/cgroup:/sys/fs/cgroup:ro opensuse423;
docker exec -it opensuse-systemd bash

Finally, you can run systemd on your openSUSE container, you can check by running systemctl commands, like restart your service or etc. for example :

systemctl list-units

Thank you, i will get back to work :D.

2 thoughts on “How To Running Systemd on openSUSE Docker Container

  1. This is awesome, I was looking for that kind of tutorial for long time.


    P.S: Same as Rubens, I had to use –privileged to get it works.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.