Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker ps shows empty list - although docker telling container exists

when calling docker ps the list is empty, although I got an id: (dcbb6aeaa06ba43fcb.....)

My steps:

  • Step 1: I created an image (imagekommando) of an running js.file:

    docker images

  • Step 2: I created a container (in background) based on my image

    docker run -d --name containerkommando imagekommando
    

    docker run -d --name containerkommando imagekommando

    I got an id! (container-id??)

  • Step 3: But docker ps shows empty list:

    docker ps

But when I repeat Step 2, I'm told, that the container (containerkommando) already exists:

docker run -d --name containerkommando imagekommando

docker run -d --name containerkommando imagekommando

Could you help me, understanding the logic behind? And how can I get the container running (by ID)?

like image 416
Max Mark Avatar asked Oct 20 '25 16:10

Max Mark


2 Answers

That means that the docker container exited with an error but clean up is required. With --rm option you can tell the docker to remove the container when the container has exited.

docker run --rm .....

Also to check the reason for the container exiting...you can use

docker logs <container_id>
like image 76
error404 Avatar answered Oct 23 '25 07:10

error404


What probably takes place here:

  1. docker run ... creates and starts your container
  2. your container exits
  3. docker ps doesn't list stopped containers (default shows just running), so it made you think that it's not there.
  4. docker run ... fails because you are trying to create and run a container with a name that already exists.

Further reading:

  • What are the possible states for a docker container?
  • Why docker container exits immediately
like image 45
tgogos Avatar answered Oct 23 '25 07:10

tgogos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!