docker/docker — pull request #7414 by crosbymichael (2014-08-05 01:26:17+00:00)
Title: Auto restart containers based on restart policy

This implements the proposal in #7226

#### Restart Policies

Using the `--restart` flag on docker run you can specify a restart policy for
how a container should or should not be restarted on exit.

** no ** - Do not restart the container when it exits.

** on-failure ** - Restart the container only if it exits with a non zero exit status.

** always ** - Always restart the container regardless of the exit status.

You can also specify the maximum amount of times docker will try to restart the
container when using the ** on-failure ** policy. The default is that docker will try forever to restart the container.

$ sudo docker run --restart=always redis

This will run the redis container with a restart policy of ** always ** so that if
the container exits, docker will restart it.

$ sudo docker run --restart=on-failure:10 redis

This will run the redis container with a restart policy of ** on-failure ** and a
maximum restart count of 10. If the redis container exits with a non-zero exit
status more than 10 times in a row docker will abort trying to restart the container.