简体   繁体   中英

Supervisor: Stop the Docker container when a process crashes

I would like to use Supervisor to run multiple processes in my Docker container, as described here, in Docker docs .

It works but the doc does not say anything about what happens when one of the processes I start crashes.

Following docker behavior logic - when a process crashes - container should stop, and probably later it should be restarted by Docker according to restart policy.

But it does not happen, If one (or all) of application I start exits - container keeps working.

How can I tell Supervisor to exit (and stop the container in this way, because I run it in nodaemon=true mode) as well, when one of monitoring processes exits/crashes?

if you want to exit the container when your process stops, don't use supervisor (or any other process manager). just run the process in your container, directly.

but more importantly: don't run multiple critical applications in your container. the golden rule of Docker containers is not 1 process per container, but 1 concern per container. that way your container can properly shut down when that 1 concern (application) exits.

even in the example you cite, they are not running 2 critical processes. they are running 1 app process and then hosting sshd in the same container for ssh access. if sshd stops, it's probably not a big deal. if the apache server stops... well, they're using supervisor to handle that and automatically restart it.

to get what you want, separate your concerns into multiple containers and just run the app in the container directly.

I found this article which describes that its sometimes valid to run multiple processes in one container.

He describes how to use honcho to create the behaviour you would like: stop the whole container when one of the processes fails.

I'am going to try this now, but I'm still a little bit in doubt because supervisord is used so much more in the docker world and is also described on their own site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM