Editing Docker Start configuration behavior and restart policy

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
#redirect [[Start configuration behavior and restart policy]]
+
To configure the '''start configuration behavior or the restart policy''' for a container (both of them), use the <code>--restart</code> flag when using the <code>docker run</code> command. The value of the <code>--restart</code> flag can be any of the following:
 +
 
 +
*Do not automatically restart the container. (the default): <code>no</code>
 +
*Restart the container if it exits due to an error, which manifests as a non-zero exit code: <code>on-failure</code>
 +
*Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted: <code>unless-stopped</code>
 +
*Always restart the container if it stops: <code>always</code>
 +
 
 +
 
 +
The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted:
 +
 
 +
<code>$ docker run -dit --restart '''unless-stopped''' redis</code>
 +
With <code>[[/docker inspect/]] CONTAINER</code><ref>https://stackoverflow.com/questions/43108227/is-it-possible-to-show-the-restart-policy-of-a-running-docker-container</ref> you can verify <code>RestartPolicy</code> configuration.
 +
 
 +
To update restart policy execute:
 +
:<code>[[docker update]]</code><ref>https://docs.docker.com/engine/reference/commandline/update/</ref> --restart=always CONTAINER_ID|CONTAINER_NAME<ref>docker update --restart=always 90bf248337dc</ref>
 +
: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 ==
 +
* {{docker}}
 +
 
 +
{{CC license}}
 +
Source: https://en.wikiversity.org/wiki/DevOps/Docker/Start_configuration_behavior_and_restart_policy

Please note that all contributions to wikieduonline may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Wikieduonline:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Advertising: