newkid
newkid

Reputation: 1468

Docker not killing containers

I'm trying to kill my docker containers with the command:

$ docker container kill $(docker ps -q)

however, the containers aren't responding.

I'm able to log into them with:

$ docker exec -it container_id bash

but any commands within the terminal hangs.

Whats interesting is somehow the process also doesn't seem to exist. I get the list of running containers with the process ids as so:

$ for i in $(docker container ls --format "{{.ID}}"); do docker inspect -f '{{.State.Pid}} {{.Name}}' $i; done
12821 /brave_carson
12661 /trusting_hoover0
12617 /peaceful_franklin
12534 /frosty_volhard
12702 /zealous_sammet
12678 /flamboyant_jang
12690 /dreamy_driscoll

When I try to kill it with kill -9 pid I get the error:

$ kill -9 12821
-bash: kill: (12821) - No such process

This is very unusual. How do I resolve this? I'd prefer not to restart docker unless it is the last and only option.

Upvotes: 0

Views: 282

Answers (2)

pszaba
pszaba

Reputation: 1064

As a side note you can use docker run ... --rm ... to automatically remove containers after stop

Upvotes: 0

BMitch
BMitch

Reputation: 265085

If you kill the container, you cannot exec into it. The container must be running for exec to work (you should get an error message from this).

When the container is not running, there should be no process. However the container definition in docker, including logs, and changes to the container filesystem, will remain until you remove it with docker container rm (same as docker rm), e.g.:

docker container rm brave_carson

Upvotes: 1

Related Questions