1

Today I tried to run my containers in detached mode and I faced some issue.

When I ran the command docker container run -d nginx, the image of nginx got pulled and the output of the container was not shown as it was in detached mode.

Then I ran the command docker container ls which we all know shows only running containers and it showed my nginx container running. Image for nginx image

Then I tried the same thing with the ubuntu image i.e. docker container run -d ubuntu but when I ran docker container ls command my ubuntu image was not running, only the nginx container was running.

Image for ubuntu image

Why is it so?

1 Answers1

7

You don't see a running container with the ubuntu image, because the container stops immediately after being started. while the nginx image starts an nginx server that keeps the container running, the ubuntu image executes a sh -c "bash" on start - bash is not a process that keeps on running after execution. You will be able to see your stopped ubuntu container with the docker ps -a

If you want to keep the ubuntu container running, you need to pass it a command that starts a process that keeps on running, e.g. docker run -d ubuntu tail -f /dev/null

Fritz Duchardt
  • 11,026
  • 4
  • 41
  • 60