Starting a system service in a Docker container

884 Views Asked by At

I am running a Docker container where the application needs to have the autofs service running, but it's not currently run by default. The container already uses supervisord to manage several background processes, so I figure I should add the service to supervisor's program list.

Is there a way to do that which isn't repeating much of the logic in /etc/init.d/autofs? Something like:

[program:autofs]
service = autofs

would be awesome but this syntax doesn't appear to be supported by supervisord. Should I call systemctl, service, or /etc/init.d/autofs directly?

1

There are 1 best solutions below

0
On

do you need the service to run on the host? In that case you may need to add the various mount points to be able to interact with the host systemd from the container and manually start the service with systemctl.

An alternative we use on Atomic Host (and that can be used on other systems as well) for managing system services in containers is what we call "system containers". We use systemd to lauch and manage a runC container. In this way you can specify the dependency on another service directly in the template configuration file for systemd.