Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 776
yam Avatar asked Sep 23 '18 05:09

yam


People also ask

Could not kill running container Cannot remove tried to kill container but did not receive an exit event?

Restart the docker service: sudo systemctl restart docker. service. Restart the Host Machine. Enter inside the container docker exec -it ContainerName /bin/bash and then Kill the container kill 1.

How long does a container stay in the running state?

1. Overview. In this tutorial, we'll explore ways to keep Docker containers running indefinitely. By default, containers run only as long as their default command executes but a common use case it´s to run them indefinitely for debugging and troubleshooting purposes.

What is container's PID 1?

PID 1 is special on linux, it is unkillable, meaning that it doesn't get killed by signals which would terminate regular processes. So, in a container, the first process that is started really must install handlers for SIGTERM , otherwise it will stick around.

How do I kill all Docker containers?

Kill All Containers Using Docker Compose If you do, killing multiple containers takes one command: docker-compose down. You could also run docker-compose without detached mode. If so, you'll just use ^C to kill all containers. And there you have it—all containers killed!


1 Answers

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.

like image 65
yam Avatar answered Sep 30 '22 02:09

yam