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"?
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.
docker stop $(docker ps -a -q) &
docker update --restart=no $(docker ps -a -q) &
systemctl restart docker
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
@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
)
@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
@zrml the --restart=always
is set on docker 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 expected
@thaJeztah , you stand correct, it was set at docker run
event. This is not part of a swarm. Thanks
You can also update the restart policy of the container to prevent it from being restarted; see the documentation for docker update
;
docker update --restart=no my-container
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.
@andrewb-ms --restart=unless-stopped
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
@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.
@thaJeztah Oh ok, got it, thanks for the clarification. :smile:
docker service rm <service-id>
works.. and followed by docker stop $(docker ps -a -q) &
docker update --restart=no $(docker ps -a -q)
I had two containers that were created with docker compose (not sure if docker-compose is related actually) and I was not able to stop the containers, they kept coming up. I tried to update with restart=no
, restart=unless-stopped
and restart=never
(the latter gave an error as never
is not supported) but none of that helped. Even removing the containers did not help at all. Running Docker version 18.03.1-ce, build 9ee9f40
You can also update the restart policy of the container to prevent it from being restarted; see the documentation for
docker update
;docker update --restart=no my-container
thx Sloved
Stopping a container with restart=always
is inconsistent:
More details here: https://stackoverflow.com/q/53003404/647991
containers which are stuck in a restart loop (because they are failing to start-up) will NOT be stopped
I suspect for those, that the restart process is already triggered (with a delay), so after the delay, a new start
will be sent to those containers
containers which are stuck in a restart loop (because they are failing to start-up) will NOT be stopped
I suspect for those, that the restart process is already triggered (with a delay), so after the delay, a new
start
will be sent to those containers
Probably. From a user point of view, it is confusing: you stop a container and sometimes it stops and sometimes it doesn't.
What about docker rm -f container_name
?
What about
docker rm -f container_name
?
No, the container will not be removed and the restar-docker-hell will be start over and over and over.
If you're in Windows, just stop the Docker Swarm docker swarm leave --force
, and, after that, stop them all.
No, the container will not be removed and the restar-docker-hell will be start over and over and over.
If you're in Windows, just stop the Docker Swarmdocker swarm leave --force
, and, after that, stop them all
That looks unrelated to this issue; if a container is part of a swarm service, stopping or removing the container will cause the swarm reconciliation loop to kick in and spin up a new container to replace it. To remove running containers of a swarm service, remove the service itself. (see https://github.com/moby/moby/issues/23704)
@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 expected
Yes, my docker container was inside a stack. So for me to stop my docker, instead of running docker stop <docker_name>
, I had to use docker stack rm <stack_name>
.
My docker container status shows UP but when I dso to container, the processes are Stopped.
Based on the samson.stdout log, can see that it always "Restarting samson".
Hello from SAMSON after detach: 21757
3-Mar-20 00:28:16.715 Samson will listen on port 40554 for local processes
3-Mar-20 00:28:16.715 Read state as 'running'
3-Mar-20 00:28:16.966 Starting personality.sh [21800] OK
3-Mar-20 00:28:17.004 Starting pfwdog.sh [21805] OK
3-Mar-20 00:28:17.039 Starting splinter [MONDO] OK
3-Mar-20 00:28:17.040 Starting cvp_server [MONDO] OK
3-Mar-20 00:28:17.041 Starting clam_server [MONDO] OK
3-Mar-20 00:28:17.042 Starting dgi_server [MONDO] Tue Mar 3 00:28:21 +08 2020 Samson has stopped: 0
Tue Mar 3 00:28:22 +08 2020 Restarting samson
Hello from SAMSON after detach: 22004
3-Mar-20 00:28:22.280 Samson will listen on port 42151 for local processes
3-Mar-20 00:28:22.280 Read state as 'running'
3-Mar-20 00:28:22.531 Starting personality.sh [22047] OK
3-Mar-20 00:28:22.570 Starting pfwdog.sh [22052] OK
3-Mar-20 00:28:22.606 Starting splinter [MONDO] OK
3-Mar-20 00:28:22.607 Starting cvp_server [MONDO] OK
3-Mar-20 00:28:22.608 Starting clam_server [MONDO] OK
3-Mar-20 00:28:22.609 Starting dgi_server [MONDO] Tue Mar 3 00:28:26 +08 2020 Samson has stopped: 0
Tue Mar 3 00:28:27 +08 2020 Restarting samson
the only thing that worked for me to kill these zombie containers was running a one liner,
sets restart=no, kills container, removes image w force
docker ps -a --format="{{.ID}}" | xargs docker update --restart=no | xargs docker stop | xargs docker rmi $(docker images -qa) --force
Most helpful comment
docker stop $(docker ps -a -q) &
docker update --restart=no $(docker ps -a -q) &
systemctl restart docker