0

I'm having trouble understanding the output of docker ps -all after starting the same docker container multiple times (because there is a problem with my understanding of docker).

To illustrate the issue:

  1. I create a docker container by issuing: docker create busybox date which returns something like b48a2a768679dd5cdb767d24f6632d6c3d37f735596bf2b5e47517b495d641af

  2. Next I do the following:

$ docker start -a b48a2a768679dd5cdb767d24f6632d6c3d37f735596bf2b5e47517b495d641af
Sat Jan 22 03:14:24 UTC 2022

$ docker start -a b48a2a768679dd5cdb767d24f6632d6c3d37f735596bf2b5e47517b495d641af
Sat Jan 22 03:14:26 UTC 2022

$ sleep 20

$ docker start -a b48a2a768679dd5cdb767d24f6632d6c3d37f735596bf2b5e47517b495d641af
Sat Jan 22 03:14:53 UTC 2022

$ docker ps -all
CONTAINER ID   IMAGE     COMMAND   CREATED              STATUS                     PORTS     NAMES
b48a2a768679   busybox   "date"    About a minute ago   Exited (0) 4 seconds ago             sad_robinson

Now I see two problems with the docker ps -all output:

  1. I think I should list all my instances of docker start -- since the output was different, I reckon each was a different start of the same container (as you can see I only see one row in the ps -all output)

  2. The output from ps -all seems to list the first start as I ran all of these commands right after the other and other than the sleep command all of them returned immediately yet the output of ps -all reflects a start time of "about a minute ago"

1 Answer 1

1

The docker ps command lists containers, and the docker start command does not create new containers, so running it multiple times will not add additional entries to the ps output. Instead, what the start is doing is taking a non-running container and running it. The same would happen automatically with a restart policy on the container. The status in the ps output is the most recent status. Starting the container changes that status, as does stopping the container.

To create a new container that would be listed in ps, that's docker container create, or just docker create, which makes the container without starting it. Typically, people just use docker run which is a combination of docker create and docker start to create new containers.

1
  • Many thanks that really helped - so a non-running container can be restarted multiple times? Commented Jan 23, 2022 at 17:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.