Setting the restart policy on a container
Before Docker 1.2, when a container exited for any reason or the Docker host was rebooted, the container had to be manually restarted using the restart
command. With the release of Docker 1.2, a policy-based restart capability was added to the Docker engine to automate restarting containers. This feature is activated using the --restart
option of the run
command and it supports container restart at Docker host boot time, as well as when container failures occur.
Getting ready
Ensure that the Docker daemon is running on the host and can be connected through the Docker client.
How to do it...
You can set the restart policy using the following syntax:
$ docker container run --restart=POLICY [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
Here is an example of using the preceding command:
$ docker container run --restart=always -d -i -t ubuntu /bin/bash
There are three restart policies to choose from:
no
: This does not start the container if it dieson-failure
: This...