We’ve found a few methods to have a Docker instance look-alike a system container
dumb-init
and rely on the cron daemon as an instance-holderdumb-init
and bash/wait
for all daemons to finish? // TODOSYS_ADMIN
and simply run systemd withinit works for ubuntu], centos and devuan! devuan is preferred, though, as the init scripts within will just work out-of-the-box.
Make sure either dumb-init
or tini
get installed within the image.
Prepare a specially crafted rc.local
within the image e.g.
#!/bin/bash # daemon1 goes to background... # daemon2 goes to background... # last daemon goes to foreground echo starting cron daemon as the instance-holder exec /usr/sbin/cron -f
and within the image itself
ENTRYPOINT ["/usr/bin/dumb-init", "--"] CMD ["/usr/bin/bash", "-c", "/etc/rc.local"]
the tini
alternative to dumb-init
should also work
ENTRYPOINT ["/usr/bin/tini", "--"] CMD ["/usr/bin/bash", "-c", "/etc/rc.local"]
one shot – this is somehow the equivalent of what the built-in tini
would do
untested
docker run -d --init pbraun9/ubuntu "bash -c /etc/rc.local"
untested
Prepare a specially crafted rc.local
within the image e.g.
#!/bin/bash echo -n cron... /usr/sbin/cron && echo done || echo FAIL wait -n
and within the image itself
# not sure that works ENTRYPOINT ["/usr/bin/dumb-init", "--"] CMD ["/usr/sbin/cron", "-f"]
It works!
DRAFT – cannot test a systemd instance on slackware
Within the image itself
...
Create an instance and run systemd within
docker run -dti --name train-shuffle --hostname train-shuffle \ --cap-add=SYS_ADMIN \ -e "container=docker" \ -v /sys/fs/cgroup:/sys/fs/cgroup \ pbraun9/ubuntu /sbin/init ^P ^Q
That does NOT work in case there’s a sheebang in rc.local
, as bash then becomes associated with the init
ENTRYPOINT ["/usr/bin/dumb-init", "--"] CMD ["/etc/rc.local"]
[WARN tini (7)] Tini is not running as PID 1 and isn't registered as a child subreaper. Zombie processes will not be re-parented to Tini, so zombie reaping won't work. To fix the problem, use the -s option or set the environment variable TINI_SUBREAPER to register Tini as a child subreaper, or run Tini as PID 1.
Docker How to run /usr/sbin/init and then other scripts on start up [closed] https://stackoverflow.com/questions/48720049/docker-how-to-run-usr-sbin-init-and-then-other-scripts-on-start-up
Startup script after /usr/sbin/init #118 https://github.com/CentOS/sig-cloud-instance-images/issues/118
The centos:centos7 image doesn’t have “service” command #28 https://github.com/CentOS/sig-cloud-instance-images/issues/118
Running systemd within a Docker Container https://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container
RUNNING SYSTEMD WITHIN A DOCKER CONTAINER https://rhatdan.wordpress.com/2014/04/30/running-systemd-within-a-docker-container/
privileged container which is running init process inside a container kills all TTY sessions on host #106 https://github.com/docker/for-linux/issues/106 –> SYS_ADMIN and cgroup
Choosing an init process for multi-process containers https://ahmet.im/blog/minimal-init-process-for-containers/
Introducing dumb-init, an init system for Docker containers https://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html
dumb-init https://github.com/Yelp/dumb-init
Run multiple services in a container https://docs.docker.com/config/containers/multi-service_container/
Tini - A tiny but valid init for containers https://github.com/krallin/tini
Releases https://github.com/krallin/tini/releases/
Tini Automated Builds https://github.com/krallin/tini-images
What is advantage of Tini? #8 https://github.com/krallin/tini/issues/8
When not to use docker run –init https://stackoverflow.com/questions/56496495/when-not-to-use-docker-run-init
Specify an init processđź”— https://docs.docker.com/engine/reference/run/#specify-an-init-process
How to use –init parameter in docker run https://stackoverflow.com/questions/43122080/how-to-use-init-parameter-in-docker-run
s6 http://skarnet.org/software/s6/