Closed
Description
What's the recommended way to terminate (permanently) containers that were started with --restart=always
? If I kill them and then restart the daemon, they come back. If I kill them, remove that container and it's image, then they stay dead. Is this intended behavior? Is there an easier way to say "kill and don't restart"?
Activity
cpuguy83 commentedon Jan 11, 2015
I'm not sure if it's intended behavior to restart a stopped container on daemon restart... but for sure
docker rm <container>
would be all that is needed, no need to remove the image.88plug commentedon Jun 21, 2017
docker stop $(docker ps -a -q) &
docker update --restart=no $(docker ps -a -q) &
systemctl restart docker
zrml commentedon Aug 29, 2017
The command above does not work for me with 17.06 CE
$ docker stop $(docker ps -a -q) &
[1] 10347
$ docker update --restart=no $(docker ps -a -q) &
[2] 10349
$ sudo systemctl restart docker95ca5f77f47f
e4729fa5a4eb
4145ccf79320
95ca5f77f47f
e4729fa5a4eb
4145ccf79320
[1]- Done docker stop $(docker ps -a -q)
[2]+ Done docker update --restart=no $(docker ps -a -q)
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4f5b57caaff3 quay.io/prometheus/prometheus:latest "/bin/prometheus -..." 11 seconds ago Up 5 seconds 9090/tcp monitoring_prometheus.1.92mo1fvdkzk19vszcqrlmlm5x
Any other suggestions please?
Thanks
cpuguy83 commentedon Aug 30, 2017
@zrml If you call
docker stop
on a container, the container will not be restarted unless you restart the daemon (and it has--restart=always
)zrml commentedon Sep 16, 2017
@cpuguy83 sorry I'm late on this (too much traveling).
The container has --restart=always.
I am able to stop it, but shortly afterwards the daemon restarts it again.
The daemon does not have a --restart=always policy in /lib/systemd/system/docker.service.
Where is that flag for that container maintained? Can I get to it and reset it to --restart=no anywhere?
Thanks
thaJeztah commentedon Sep 16, 2017
@zrml the
--restart=always
is set ondocker run
. If the container you're stopping is part of a swarm service though, docker will start a new container to replace it; that's expectedzrml commentedon Sep 17, 2017
@thaJeztah , you stand correct, it was set at
docker run
event. This is not part of a swarm. Thanksvharsh commentedon Oct 31, 2017
Helpful
https://stackoverflow.com/questions/27283131/how-can-i-stop-and-delete-a-docker-container-launched-with-restart-always-option
thaJeztah commentedon Oct 31, 2017
You can also update the restart policy of the container to prevent it from being restarted; see the documentation for
docker update
;andrewb-ms commentedon Jan 17, 2018
The restart policy suggestion doesn't work. This seems really broken - there needs to be a "docker kill" command that shuts down the container and nukes it from the restart policy.
cpuguy83 commentedon Jan 17, 2018
@andrewb-ms
--restart=unless-stopped
lucsrods commentedon Feb 7, 2018
None of the solutions here worked for me, but after I verified the services (
docker service ls
) and removed them (docker service rm <service-id>
), I was finally able to stop the containers.I'm on Docker version 17.12.0-ce
thaJeztah commentedon Feb 7, 2018
@Lucasar that's a different situation (not related to
--restart=always
), and the intended behaviour; if you start a swarm service, docker swarm reconciles the service's actual state with the desired state. That means that if you told it to start (e.g.) 5 instances of the service, and an instance of that service goes down (whatever the reason), Docker will create a new instance to replace the one that failed.16 remaining items