user1050619
user1050619

Reputation: 20906

Docker process not starting in the background

Im trying to create 2 docker process in the background.Both creates

  1. Nginx - Create a background image
  2. docker ps - list this process
  3. Ubuntu - Create a background image
  4. docker ps - list only the nginx.
  5. docker ps -a - list both the containers

My questions is related to 4) - Why the ubuntu image is not listed when I try 'docker ps'

enter image description here

Upvotes: 0

Views: 1828

Answers (1)

BMitch
BMitch

Reputation: 264986

docker run ubuntu without any further args will use the default command for this image the follows the below logic:

  1. The command is a shell that takes its input from stdin.
  2. Once stdin is closed the shell will exit.
  3. When the process that starts the container exits, the container is stopped.
  4. Docker ps without the -a will only list the running containers.

Note that the process for nginx, rather than being a shell, is a web server that does not depend on stdin.

To see the ubuntu container continue to run, but in the background, you can include the -id options on the command line, e.g.:

$ docker run -id ubuntu
ef672b3750e62c309afdf656d7d82951d302db79274b7369e620e5381f806654

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                  PORTS               NAMES
ef672b3750e6        ubuntu              "/bin/bash"         7 seconds ago       Up Less than a second                       brave_newton

Upvotes: 2

Related Questions