Bootstrap FreeKB - Docker - Restart a container using the --restart option
Docker - Restart a container using the --restart option

Updated:   |  Docker articles

When creating a container using the docker run command, the --restart option can be used to start the Docker container if the Docker server or daemon is restarted or if the host server is restarted. 

It is important to recognize that if you do not use the --restart option when creating or starting a Docker container using the docker run commandthe Docker container will NOT start up if the Docker server or daemon is restarted or if the host server is restarted. The restart options are:

  • no
  • on-failure:[max-retries]
  • always - The Docker container will be started if the Docker server or daemon is restarted or if the host server is restarted
  • unless-stopped - The Docker container will be started if the Docker server or daemon is restarted or if the host server is restarted as long as the Docker container was not manually stopped
docker run --restart unless-stopped --name my-container my-image:latest

 

Of if the container already exists the docker update command can be used.

sudo docker update --restart unless-stopped my-container

 

You can use the docker inspect command to view the JSON for the container.

~]$ sudo docker inspect my-container | jq .[].HostConfig.RestartPolicy
{
  "Name": "unless-stopped",
  "MaximumRetryCount": 0
}

 

After a Docker container has been created, the docker restart command can be used to restart the container.

docker restart my-container

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter d35bd5 in the box below so that we can be sure you are a human.