Showing posts with label docker automatic restart. Show all posts
Showing posts with label docker automatic restart. Show all posts

Solved: How to restart a docker container automatically on crash

In this post we will see how we can restart a container automatically if it crashes.
If you want a Docker container to always restart use:-
docker run -dit --name cldvds-always-restart --restart=always busybox
But if you want container to always restart unless it is explicitly stopped  or restarted, use:-
docker run -dit --name cldvds-except-stop --restart unless-stopped busybox
In case you want the container to stop after 3 restart attempt use below command.
docker run -dit --name cldvds-restart-3 --restart=on-failure:3 busybox
You can see the logs of a container using
docker logs cldvds-restart-3
If you want to change the restart policy of running container you can do it with “docker update” e.g. here we are changing restart attempt from 3 to 4 of container cldvds-restart-3.
docker update --restart=on-failure:4 cldvds-restart-3