Docker - Restart a container using the docker run --restart option
by
Jeremy Canfield |
Updated: April 15 2024
| 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 command, the 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 my-container
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