Docker does do some management of daemonized containers: if the system shuts down, then when the Docker daemon starts it will also restart any containers that were running at the time the system shut down. But if the container exits on its own or the kernel (or a user) kills the container while it is running, the Docker daemon won't restart it. In cases where you do want a restart, a process manager makes sense.
I don't know runit
so I can't give specific configuration guidance. But you should probably make the process manager communicate with the docker daemon and check to see if a given container id is running (docker ps | grep container_id
or equivalent, or use the Docker Remote API directly). If the container has stopped, use Docker to restart it (docker run container_id
) instead of running a new container. Or, if you do want a new container each time, then begin with docker run -rm
to automatically clean it up when it exits or stops.
If you don't want your process manager to poll docker, you could instead run something that watches docker events
.
You can get the container_id when you start the container as the return value of starting a daemon, or you can ask Docker to write this out to a file (docker run -cidfile myfilename
, like a PID file)
I hope that helps or helps another runit
guru offer more detailed advice.