Difference between revisions of "Docker Start configuration behavior and restart policy"

From wikieduonline
Jump to navigation Jump to search
Line 18: Line 18:
  
 
== See also ==
 
== See also ==
* [[devOps/Docker/docker inspect|docker inspect]]
+
* [[docker inspect]]
  
 
{{CC license}}
 
{{CC license}}
 
Source: https://en.wikiversity.org/wiki/DevOps/Docker/Start_configuration_behavior_and_restart_policy
 
Source: https://en.wikiversity.org/wiki/DevOps/Docker/Start_configuration_behavior_and_restart_policy

Revision as of 06:53, 16 December 2019

To configure the start configuration behavior or the restart policy for a container (both of them), use the --restart flag when using the docker run command. The value of the --restart flag can be any of the following:

  • Do not automatically restart the container. (the default): no
  • Restart the container if it exits due to an error, which manifests as a non-zero exit code: on-failure
  • Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted: unless-stopped
  • Always restart the container if it stops: always


The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted:

$ docker run -dit --restart unless-stopped redis With /docker inspect/ CONTAINER[1] you can verify RestartPolicy configuration.

To update restart policy execute:

docker update[2] --restart=always CONTAINER_ID|CONTAINER_NAME[3]
If the container is started with “--rm” flag, you cannot update the restart policy for it. The AutoRemove and RestartPolicy are mutually exclusive for the container.


See also

Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.

Source: https://en.wikiversity.org/wiki/DevOps/Docker/Start_configuration_behavior_and_restart_policy

Advertising: