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.
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.
The docker compose start command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With