If you want a Docker container to always restart use:-
docker run -dit --name cldvds-always-restart --restart=always busyboxBut 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 busyboxIn 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 busyboxYou can see the logs of a container using
docker logs cldvds-restart-3If 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