Container exits immediately: the command was overridden
Easy

Problem

web won't stay up. docker ps never shows it; docker ps -a shows it Exited (0) seconds after starting. The image is the stock nginx:alpine, which normally runs forever. There's no crash, no error — exit code 0 — yet it refuses to serve. Figure out why an nginx container exits cleanly instead of running, and get it serving.

Initial setup

  • webnginx:alpine, Exited (0), deployed seconds ago.

Example interaction

$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       STATUS                    NAMES
9e9e9e9e9e9e   nginx:alpine   "nginx -t"    Exited (0) 1 minute ago   web

$ docker logs web
nginx: configuration file /etc/nginx/nginx.conf test is successful

Acceptance

You've solved it when:

  • You've established the container exits because its command was
overridden to a one-shot (nginx -t, a config test) instead of the image's default that runs the server — so it does its job and exits 0. This is not a crash, a bad image, or a config error (the config test even passed).
  • You've brought web up running by launching it with the image's
default command (no overriding argument), i.e. docker run ... nginx:alpine without the trailing nginx -t.

Constraints

  • Tools: docker CLI only.
  • End state: web in status == running (serving, not a one-shot).

Follow-up

  1. docker run nginx:alpine nginx -t vs docker run nginx:alpine — what
does the trailing nginx -t do to the image's CMD?
  1. Why is Exited (0) (clean exit) a useful clue that the container *did
what it was asked*, versus Exited (1)/(137)?
  1. How does a command: line in a compose file produce the same trap?
Live session
Code
SavedNo commands yet