How to stop a docker container which started with `--restart=always`

Docker

Docker Problem Overview


Is there any way to stop a docker container which started with --restart=always like following

sudo docker run -it --restart=always <image_id>

Docker Solutions


Solution 1 - Docker

Here's the mighty eagle that docker has recently included. :D

You can update docker container.

use sudo docker update --restart=no <container_id> to update --restart flag of the container.

Now you can stop the container.

Solution 2 - Docker

You should be able to just use docker stop and then docker rm to make sure the container doesn't restart when the daemon restarts.

Your question is an issue on the docker github and someone has made some comments about to how to solve here

> I'm not sure if it's intended behavior to restart a stopped container on daemon restart... but for sure docker rm would be all that is needed, no need to remove the image.

Solution 3 - Docker

If you use docker stop or docker kill, you're manually stopping the container so it will not restart. You can do some tests about restart policies: restarting the docker daemon, rebooting your server, using a CMD inside a container and running an exit...

See this answer for more details:

https://serverfault.com/a/884823/381420

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRafaf TahsinView Question on Stackoverflow
Solution 1 - DockerRafaf TahsinView Answer on Stackoverflow
Solution 2 - DockerzhqiatView Answer on Stackoverflow
Solution 3 - DockerAchraf JEDAYView Answer on Stackoverflow