yam
yam

Reputation: 1463

Zombie docker container that can't be killed

I use docker-compose to create a bunch of containers and link them together. For some of the container definitions, I might have restart: always as the restart policy.

Now I have a postgres container that respawns back to life if stopped.

$docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
a8bb2b781630        postgres:latest     "docker-entrypoint.s…"   About an hour ago   Up About an hour    5432/tcp            dcat_postgres.1.z3pyl24kiq2n4clt0ua77nfx5
docker stop a8bb2b781630
a8bb2b781630
$ docker rm -f a8bb2b781630
a8bb2b781630
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
93fa7b72c2ca        postgres:latest     "docker-entrypoint.s…"   12 seconds ago      Up 4 seconds        5432/tcp            dcat_postgres.1.oucuo5zg3y9ws3p7jvlfztflb

Using docker-compose down in the dir that started the service doesn't work either.

$ docker-compose down
Removing dcat_postgres_1 ... done
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7ee7fb0e98cd        postgres:latest     "docker-entrypoint.s…"   13 seconds ago      Up 5 seconds        5432/tcp            dcat_postgres.1.jhv1q6vns1avakqjxdusmbb78

How can I kill a container and keep it from coming back to life?

EDIT: The container respawns even after restarting the Docker service.

Docker - 18.06.1-ce-mac73 (26764)

macOS High-Sierra, (10.13.6)

Upvotes: 18

Views: 23357

Answers (3)

anon
anon

Reputation:

I ran into this issue when playing around with an Ansible deployment of Matrix. I just could not kill it until I did this

CONTAINERS=$(echo $(sudo docker ps | grep matrix | awk '{print $1;}'))
sudo docker container stop $CONTAINERS && sudo docker system prune -a

Here' I'm grepping on matrix but you could use as you like. It's really the prune right after the stop that does the zombie removal.

Upvotes: 0

VonC
VonC

Reputation: 1326636

Can you try an option like moby/moby issue 10032:

docker stop $(docker ps -a -q) &
docker update --restart=no $(docker ps -a -q) &
systemctl restart docker

(this assume here you have only one running container: the one you cannot prevent to start)

A docker rm -f should be enough though, unless you are using docker with a provision tool like Puppet.

As it turned out, another process (other than docker itself) was responsible for the container to restart (here docker swarm)


Update 2020/2021: For multiple containers, possibly without having to restart the docker daemon

docker ps -a --format="{{.ID}}" | \
 xargs docker update --restart=no | \
 xargs docker stop

Check if you need, as in the issue, remove the images as well ( | xargs docker rmi $(docker images -qa) --force)

Upvotes: 11

yam
yam

Reputation: 1463

I figured it out. Turns out it was related to docker swarm. I had experimented with it at some point without fully understanding what it is and what it does and apparently it just stayed there.

All I had to do was:

docker swarm leave --force

and it worked like a head-shot to an actual zombie.

Upvotes: 15

Related Questions