Unable to stop, kill or remove Docker container

Viewed 15392

I've got a container running for 5 weeks now which I can neither stop nor kill nor remove. docker ps shows this (both containers cannot be removed actually):

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
431a850b384f        f99983306232        "cmd /c 'start /B C:…"   5 weeks ago         Up 5 weeks          0.0.0.0:80->80/tcp   dockercompose18429431017078490850_xxx_1
e31f0b74a8cb        50eef858d93d        "cmd /c 'start /B C:…"   6 weeks ago         Up 6 weeks          0.0.0.0:80->80/tcp   dockercompose15856640072218908353_xxx_1

docker stop e31 and docker kill e31 just hung up and do nothing. docker rm e31 shows error:

Error response from daemon: removal of container e31 is already in progress

If I run docker inspect e31 I see the container is running, it's not dead:

    "Id": "e31f0b74a8cb8225d5104f8de7e1c583ed1852133ad2870015017b09d3df8dfa",
    "Created": "2019-05-08T06:57:24.3143863Z",
    ...
    "State": {
        "Status": "running",
        "Running": true,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 1324,
        "ExitCode": 0,
        "Error": "",
        "StartedAt": "2019-05-08T06:57:30.3396878Z",
        "FinishedAt": "0001-01-01T00:00:00Z"
    },
  ...

How to get rid of it?

System info:

  • Server Version: 19.03.0-rc2

  • Operating System: Windows 10 Pro Version 1903 (OS Build 18362.175)

8 Answers

I have also encountered this a few times. What I did to stop the 'hung' container was -

  1. docker ps to display container ID
  2. net stop docker - stop docker engine (Note all containers will stop)
  3. Delete folder in c:\programdata\docker\containers whose name starts with the ID from step 1
  4. net start docker - start docker engine

Unfortunately the docker service still has to be stopped and started but at least I didn't have to re-install.

For urgent cases, when even docker rm -f is does not help, it can be solved by stopping deamon and manually removing container:

sudo systemctl stop docker
sudo rm -rf /var/lib/docker/containers/<CONTAINER_ID>
sudo systemctl start docker

That may sound too radical but I've just reinstalled Docker. The redundant containers have gone. Finally.

For us it was an update that changed the docker.service config on RHEL.

Solution

docker rm -f <container-id>
systemctl daemon-reload
systemctl restart containerd
systemctl restart docker
docker-compose up -d

The Error we were receiving

docker-compose up -d --force-recreate
Recreating 952ba6a5bbc4_my-app ... error
t: connection refused: unknown'
​
ERROR: for 952ba6a5bbc4_my-app  Cannot start service my-app: b'dial unix \x00/run/containerd/s/086e56: connect: connection refused: unknown'
​
ERROR: for my-app  Cannot start service my-app: b'dial unix \x00/run/containerd/s/086e56: connect: connection refused: unknown'
ERROR: Encountered errors while bringing up the project.```

I have faced the same problem multiple times. Error response from daemon: removal of container docker_container_id_goes_here is already in progress

Restart your docker and run the following command in your powershell or terminal
docker rm docker_container_id_goes_here

For Mac and Windows users, an easy way is to use Docker Desktop.

You kill a container by it's name, from the output on the OP the right command should be:

docker kill dockercompose15856640072218908353_xxx_1

See here for more info. Give it a try and let me know if it worked

Well try the below two commands, First stop the container and then remove it if they are from created using the Dockerfile.

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

For docker-compose thing use this command to remove the attached containers

docker-compose down
Related