To a first approximation, commands like systemctl
, initctl
, service
, or start
just don't work in Docker and you should find a different way to do what you're attempting.
Stylewise, the standard way to use a Docker container is to launch some sort of service in the foreground. As one specific example, the standard Redis image doesn't go through any sort of init script; it just runs
CMD ["redis-server"]
In most Docker images it's unusual to even so much as launch a background process (with the shell &
operator). It's not usually necessary and in Dockerfiles the interaction with the RUN
directive has confused some people.
In the specific case of systemctl
, it requires an extremely heavyweight init system that is not just a process manager but also wants to monitor and manage kernel-level parameters, includes a logging system, runs an inter-process message bus, and some other functionality. You can't run systemd under Docker without the container being --privileged
, which gives the container the ability to "escape" on to the host system in some unfortunate ways.