3

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)?

tgogos
  • 23,218
  • 20
  • 96
  • 128
Max Mark
  • 71
  • 2
  • 9

5 Answers5

2

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>
error404
  • 2,684
  • 2
  • 13
  • 21
2

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:

tgogos
  • 23,218
  • 20
  • 96
  • 128
1

In Docker, a container is automatically exited when the task is finished. You have to specify a correct entrypoint to keep your docker container up.

You can check the exited containers with the command docker ps -a. This exited container will prevent you from using the name again.

So, you may want to use docker rm <container-name> before creating your new container. In a test environement, you can also use docker system prune to clean all unused container/networks.

Feuillebug
  • 41
  • 3
0

docker ps only shows the active containers (the running ones).

Your container most probably exited right after you started it. You can use the container ID and do docker logs <container-id> to examine the reason why the container failed.

If you want to see the stopped containers together with the running containers you can do docker ps -a to get a list of all these.

RoyB
  • 3,104
  • 1
  • 16
  • 37
0

Execute

docker logs <CONTAINER ID> 

to view the logs of docker container run.

I faced a similar issue found out there was space issue win my docker. After clearing space the container was able to run.

user2120239
  • 135
  • 2
  • 10