10

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.

5
  • I don't know if this works with containers in "created" state, please give a try to docker kill you can get more info running docker kill --help. Once you kill the containers and bring them into "exited" state, you'll be able to remove them. Commented Apr 4, 2018 at 7:25
  • @Mark It's not running so I cannot kill it. Cannot kill container: bae7a9324bc8: Container ... is not running. Commented Apr 4, 2018 at 7:42
  • 1
    Yep, I cannot reproduce a container hung in "created" state easily, but I have another idea that you can try: docker container prune --force. This will remove all stopped containers, so be careful. Commented Apr 4, 2018 at 7:45
  • @Mark thanks, it works. I tried docker system prune before but it did not work. Not sure what are the differences between 2 commands. Btw, you can write an answer so I can accept it. Commented Apr 4, 2018 at 7:54
  • Great! Happy we figured it out. I posted the answer. Commented Apr 4, 2018 at 7:57

3 Answers 3

12

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!

Sign up to request clarification or add additional context in comments.

Comments

1
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

1 Comment

Thanks for your help. However, it still hung up in docker rm command. Also, no volume is associated with these containers.
0

I have just resolved this issue on our CI environment.

We had a container stuck in Created status. docker rm container_id, docker rm container_name, docker inspect container_id and docker kill container_id all failed with no such container like responses.

However, docker start container_id worked.

Followed by docker stop container_id and docker rm container_id which now worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.