David Z
David Z

Reputation: 7041

Docker container ps or ls doesn't show running Containers

Here is an example on my CLI:

$ docker pull hello-world
$ docker run hello-world 

It shows empty when ls/ps

$ docker container ls
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$ docker container ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

It shows up only when I use -a but it'd suggest the containers are actually not actively running.

$ docker container ls -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                    NAMES
    96c3e42ae83a        hello-world         "/hello"                 11 seconds ago      Exited (0) 8 seconds ago                            jovial_rosalind
    dcaed0ba308f        registry            "/entrypoint.sh /etc…"   42 minutes ago      Created                    0.0.0.0:5000->5000/tcp   registry

Have I missed something?

Upvotes: 1

Views: 3626

Answers (1)

Leonardo Dagnino
Leonardo Dagnino

Reputation: 3215

Looks like your container exited right away. Is it meant to be interactive? (like running bash, or needing any user interaction?) if it is, you should run it like this to attach a terminal to it:

docker run -ti hello-world

If not, what does your hello program do? If it is not something that will keep running, then the container will stop whenever it exits.

Also keep in mind that, unless you pass docker run the -d/--detach flag, it will only return after the container has stopped - so if it returns right away, that means your container has already stopped.

You may want to use one of these to get a bash shell in the container to debug your problem:

docker run -ti hello-world bash
docker run --entrypoint bash -ti hello-world

To understand the difference between them, you can read the documentation on ENTRYPOINT and COMMAND.

Upvotes: 2

Related Questions