Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to stop, kill or remove Docker container

Tags:

docker

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)

like image 812
Serhii Shushliapin Avatar asked Jun 19 '19 18:06

Serhii Shushliapin


People also ask

How do I force stop a docker container?

docker rm -f The final option for stopping a running container is to use the --force or -f flag in conjunction with the docker rm command. Typically, docker rm is used to remove an already stopped container, but the use of the -f flag will cause it to first issue a SIGKILL.

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 do I stop a docker container while running?

Note that pressing `Ctrl+C` when the terminal is attached to a container output causes the container to shut down.


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

like image 196
Neil Riach Avatar answered Sep 27 '22 20:09

Neil Riach


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
like image 37
Athlan Avatar answered Sep 27 '22 19:09

Athlan