In the previous scenarios we've launched some containers, but like any process, containers can crash. This scenario will explore how you can keep containers live and automatically restart them if the crash unexpectedly.
Step 1 - Stop On Fail
Docker considers any containers to exit with a non-zero exit code to have crashed. By default a crashed container will remain stopped.
We've created a special container which outputs a message and then exits with code 1 to simulate a crash.
You can launch an instance using
docker run -d --name restart-default scrapbook/docker-restart-example
If you list all the containers, including stopped, you will see the container has crashed
docker ps -a
While the logs will output our message, which in real-life would hopefully indicate information to help us diagnose the issue.
docker logs restart-default