Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot remove Docker container with status "Created"

Tags:

docker

While trying to build docker image to my application, somehow I accidentally create 2 containers with status Created.

$ docker ps -a

CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                      NAMES
597a3d226a08        2eba970a4fc8          "entrypoint.sh"          43 hours ago        Created                                        pedantic_almeida
bae7a9324bc8        b0898d035451          "entrypoint.sh"          43 hours ago        Created                                        zen_franklin

The problem is I cannot do anything with these containers. docker rm/restart/inspect <container-id> all hangs up indefinitely with no message printed. However, starting new container from these 2 images work fine.

So my question is how to remove these 2 containers? Please tell me if you need any additional information.


Docker version: 18.03.0-ce.

like image 215
hgminh Avatar asked Apr 04 '18 05:04

hgminh


People also ask

How do you remove a stuck container?

The best way to get rid of dead container processes is to restart your docker service. I was unable to remove a container as it was stuck in restarting status, I just restarted the docker service and it worked for me.

Can we delete docker image if container is running?

You cannot remove an image of a running container unless you use the -f option. To see all images on a host use the docker image ls command.


2 Answers

You can use the below command to remove the two containers hung in "created" state:

docker container prune --force

This will remove all stopped containers, so be careful!

like image 187
takacsmark Avatar answered Sep 25 '22 03:09

takacsmark


docker volume rm $(docker volume ls -qf dangling=true)
docker rm $(docker ps -q -f 'status=created')

After execution of the above commands, restart docker by,

service docker restart
like image 41
Mayank Srivastava Avatar answered Sep 22 '22 03:09

Mayank Srivastava