Is there any way to stop a docker container which started with --restart=always
like following
sudo docker run -it --restart=always <image_id>
Is there any way to stop a docker container which started with --restart=always
like following
sudo docker run -it --restart=always <image_id>
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.
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.
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:
TL;DR
Also check docker swarm if there are any stacks that spin up containers there. Simply run docker stack ls
followed by docker rm <stack_name>
.
Longer version
This is not exactly an answer to your question, but I had a very similar issue where containers kept spinning up even if I ran docker update --restart=no <container_id>
, docker stop <container_id>
and docker rm <container_id>
. These were some old containers, so I had no clue how I generated them.
After some Googling, I realized that it was a docker swarm stack that kept spinning up containers. By running docker stack ls
followed by docker rm <stack_name>
, I was able to stop the auto spin-up of the containers and thus remove them entirely.