Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose restart container if service is dead

Is it possible to restart container in docker-compose if service that is running inside it returns exit code different than 0? docker-compose.yml option restart: always doesn't work that way. Is there any way to solve it or is this a service issue and I should look for the answer inside of the container?

I use supervisord but adding option autorestart=true doesn't work even if service crashes with exit code 255 - the RUNNING_PID file (created by system) is not being deleted.

Thanks for any reply.

like image 605
Thomas Avatar asked Jul 14 '16 14:07

Thomas


People also ask

Does Docker compose restart container on failure?

no: Containers won't restart automatically. on-failure[:max-retries]: Restart the container if it exits with a non-zero exit code, and provide a maximum number of attempts for the Docker daemon to restart the container. always: Always restart the container if it stops.

Does Docker compose up restart container?

The docker compose start command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.

How do I force a container to restart?

If you want to restart your container that is already stopped then you can use the docker start command to restart the container. Just like we used it when we created our container. There is a docker restart command which can be used to restart the container which is already running in the background.


1 Answers

restart: always will restart the container regardless of the exit code, so even if exit code of the process running inside the container is 0. I'm using restart: on-failure and it does exactly what you describe. It restarts the container on a non zero exit code of the process. After the process exits and it is not restarted you can check the exit code using docker-compose ps

like image 152
Gergely Toth Avatar answered Oct 17 '22 13:10

Gergely Toth