Difficulty: Beginner
Estimated Time: 10 minutes

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.

This scenario has introduced how you can keep alive containers even after they crash.

Ensuring Uptime

Step 1 of 3

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