I am trying to see if I can run systemd inside a docker container (which is running arch linux in the container).
I start docker with all capabilities, and bind mount in cgroups:
docker run -it --rm --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro ..
however, if I try to run the systemd binary:
Trying to run as user instance, but the system has not been booted with systemd.
Trying to find out how to init things correctly to systemd starts.
Best Answer
Here my master pice :D running systemd inside a docker container with ubuntu :D I Got Ubuntu working with systemd inside docker
GitHub Repo for my docker-systemd container
Output:
Update 2021
A lot of Patches got Submitted to diffrent Projects like the docker upstream repos by REDHAT. To be More clear my frind David Walsh @ REDHAT did also post a lot about that. https://developers.redhat.com/blog/author/rhatdan/.
Running SystemD Without additional Privileges requires
/run
as a tmpfs./sys/fs/cgroup
read/only./sys/fs/cgroup/systemd
read/write./etc/machine-id
Needs to Contain a Uniqe MachineIDSIGRTMIN+3
as stopsignal as sigterm will not work/var/log/journal
If it does not exist it will write to memoryNote: The Stopsignal flag can be droped when your dockerfile contains
STOPSIGNAL SIGRTMIN+3
See the full Post. https://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container/
Note: Today with Podman this would be even more simple read about it here: https://developers.redhat.com/blog/2019/04/24/how-to-run-systemd-in-a-container/