Launching multiple Docker containers with supervisor

1.3k Views Asked by At

I've got a number of Docker containers which I would like to start using supervisor. The problem I have is that supervisor requires commands to be blocking to keep track of them.

The command docker run my/container:tag is unfortunately non-blocking, i.e. it returns immediately spawning a process.

The docker container gets launched (actually 2 and sometimes 4 instances which may be related), but supervisor indicates an error "FATAL Exited too quickly (process log may have details)".

Can supervisor be used to run Docker containers?

Update

I had the -d option also on from some earlier trials which cause -i to not work as expected (aren't they the opposite and shouldn't they prompt some sort of error?). When I run with -i in my supervisor.conf, I get this error time="2015-06-27T14:14:29+10:00" level=fatal msg="cannot enable tty mode on non tty input".

I've also tried to run without -i and it successfully starts the docker container. Unfortunately a sudo supervisorctl stop app does not actually stop the docker container. Is supervisor unable to control docker or do I really need to run with the -i option and fix this tty error somehow?

Update 2

The tty error came from also having the -t option in my docker run command. I removed it. However, supervisorctl is still not able to stop the docker run. While it doesn't give an error when running and supervisorctl status app says it has stopped with docker ps I see that the container is actually still running.

2

There are 2 best solutions below

2
On BEST ANSWER

if you run your container with the -i option, it will block

docker run -i my/container:tag

3
On

You need to run container in interactive mode. This would be the blocking call and if you are blocking until the new process exits then following is the correct command:

docker run -i -t my/container:tag