On one of my machines, I host a couple services using docker-compose. I
wanted to start/restart/stop these using the default init/service manager used
on the machine, openrc. This would allow them to start/stop automatically
with Docker (which coincides with the machine powering on or off,
I’ve set this up through a single docker-compose meta-service. To add new
docker-compose projects to be managed, all I need to do for openrc
configuration is creating a symlink, and configure the path to the
The meta-service lives at /etc/init.d/docker-compose, just like all other
services managed by openrc. This file is quite straightforward. To start off,
a number of variables are set and exported.
One of the services I use is also configured with its own external network. I
want it to be created if it doesn’t exist, to ensure that the service can start
up properly. I do not want it to be removed, so I left that out.
And lastly, there’s the four simple functions to declare dependencies,
configure how to start or stop, and how to get the status of the service.
Now, to actually create a service file to manage a docker-compose project, a
symlink must be made. I’ll take my
botamusique service as an example.
This service can’t start just yet, as there’s no $COMPOSE_PROJECT_DIRECTORY
configured for it yet. For this, a similarly named file should be made in
/etc/conf.d. In here, any variable used by the service can be configured.
In my case, it only pertains the $COMPOSE_PROJECT_DIRECTORY variable.
And that’s it. For additional docker-compose projects I need to make only a
symlink and a configuration file. If I discover a bug or nuisance, only a
single file needs to be altered to get the benefit on all the docker-compose
For reference, here’s the full /etc/init.d/docker-compose file.