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 --privileged -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.
4 Comments
Rubens · January 3, 2018 at 10:36 am
Thank You. Very good.
In “Run the container” I add –privileged
Davide · April 16, 2019 at 3:35 pm
This is awesome, I was looking for that kind of tutorial for long time.
Thanks
P.S: Same as Rubens, I had to use –privileged to get it works.
Vishwanath S Manvi · May 16, 2020 at 5:07 pm
Great article! Very helpful 🙂
One point, this works with “–cap-add CAP_SYS_ADMIN” instead of enabling full privileged mode (–privileged)
crazy-matt · February 15, 2021 at 8:22 pm
Thanks a lot! Very helpful