Serhii Shushliapin
Serhii Shushliapin

Reputation: 2708

Unable to stop, kill or remove Docker container

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:

Upvotes: 18

Views: 35768

Answers (11)

Ahmad Khalili
Ahmad Khalili

Reputation: 1

I Use this command for kill all unused containers and it's work

# Remove all stopped containers
docker container prune -f

Upvotes: 0

rrob
rrob

Reputation: 417

[SOLVED] UPDATE 2024 - Ubuntu 22.04 / Docker 26.1

In my case this container freezes whole docker, so Im updating solution from Athlan with killing all docker processes:

KILLING DOCKER FROM MEMORY AND STOPING THE SERVICE

sudo killall dockerd
sudo pkill -f docker
sudo systemctl stop docker
sudo rm -rf /var/lib/docker/containers/<CONTAINER_ID>
sudo systemctl start docker

Plus if you want to remove all remaining UNUSED resources, you can run:

# one by one:
sudo docker container prune --force
sudo docker volume prune -a --force
sudo docker image prune -a --force
sudo docker network prune --force

# or all togehter:
sudo docker system prune

TOTAL DOCKER ANNIHALATION

If previous didnt solve your problem, you can reinstall docker. After stoping docker, you can wipe it from your system like this: (https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine)

sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

Then you can proceed with fresh installation: (https://docs.docker.com/engine/install/ubuntu/#installation-methods)

I rebooted os between uninstall and install just to be sure. I recommend.

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Upvotes: 0

Artem Pavlovskii
Artem Pavlovskii

Reputation: 29

Twice in my experience the issue was due to the docker compose which produced a zombie process. The process name was docker compose up. Find the zombie with htop and kill its parent

Upvotes: 0

ingenious
ingenious

Reputation: 772

Use docker system prune to clean docker and then stop or remove your container.

Upvotes: -1

Athlan
Athlan

Reputation: 6629

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

Upvotes: 10

DJDaveMark
DJDaveMark

Reputation: 2855

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.```

Upvotes: 2

Devendra Lattu
Devendra Lattu

Reputation: 2812

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

Upvotes: -1

Neil Riach
Neil Riach

Reputation: 134

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.

Upvotes: 12

Serhii Shushliapin
Serhii Shushliapin

Reputation: 2708

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

Upvotes: 1

Farrukh Faizy
Farrukh Faizy

Reputation: 1235

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

Upvotes: -3

ReynierPM
ReynierPM

Reputation: 18690

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

Upvotes: -2

Related Questions