Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it reasonable to run docker processes under runit/daemontools supervision

Tags:

docker

runit

I have been running docker processes (apps) via

docker run …

But under runit supervision (runit is like daemontools) - so runit ensures that the process stays up, passes signals etc.

Is this reasonable? Docker seems to want to run its own demonization - but it isn't as thorough as runit. Furthermore, when runit restarts the app - a new container is created each time (fine) but it leaves a trace of the old one around - this seems to imply I am doing it in the wrong way.

Should docker not be run this way?

Should I instead set up a container from the image, just once, and then have runit run/supervise that container for all time?

like image 860
Michael Neale Avatar asked Oct 31 '13 11:10

Michael Neale


People also ask

How many processes can run in a Docker container?

Container-based application design encourages certain principles. One of these principles is that there should just be one process running in a container. That is to say, a Docker container should have just one program running inside it.

Can a Docker container run multiple processes?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

What is an init process Docker?

The init process is responsible for starting the rest of the system, such as starting the SSH daemon, starting Apache/Nginx, etc. Each of them may in turn spawn further child processes. Each process can spawn child processes, and each process has a parent except for the top-most process.


1 Answers

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.

like image 95
Andy Avatar answered Oct 04 '22 02:10

Andy