How to automatically track and reload docker container when it crashes?

I am currently running two virtual servers with offical ghost image and nginx-proxy image, here is my extension.

 docker run -d -p 86:2368 --name home -e "VIRTUAL_HOST=hostname.com" ghost docker run -d -p 85:2368 --name home-blog -e "VIRTUAL_HOST=blog.hostname.com" ghost 

They all work well, but after a while (sometimes hours or a day) one of the virtuoso servers will break down and I have to restart the container for it to work.

I wonder if there is any solution for automatically monitoring the docker container and restarting it if it is missing?

+6
source share
2 answers

You should use --restart ( docs ):

 docker run -d -p 86:2368 --restart always --name home -e "VIRTUAL_HOST=hostname.com" ghost 
+13
source

In fact, most likely the main application of your container crashed, not your container.

When the process with identifier No. 0 stops or a failure occurs in the container, the container automatically stops.

For your concern, the restart option (from the docker launch command) is one of the possibilities, as Andy claims.

Another possibility is to use a supervisor as the main container process. Your application will be launched and supervised by the supervisor. Supervisord will provide you with many options to deal with the collapse of your application. You have many useful options for registration, signal processing ...

See https://docs.docker.com/articles/using_supervisord/ and http://supervisord.org/ for more details.

+4
source

Source: https://habr.com/ru/post/986532/


All Articles