Container exits immediately with code 0: the entrypoint daemonizes and PID 1 returns
Easy

Problem

You started the worker service, but it's not in docker ps. It vanished within a second of starting:

$ docker run -d --name worker ingest-worker:2.0
a9f17c4e8b30...
$ docker ps
CONTAINER ID   IMAGE   COMMAND   ...   STATUS   ...   NAMES
# (worker is not listed)

There's no crash and no error. Find out why the container won't stay up and state the fix.

Initial setup

  • workeringest-worker:2.0, started with docker run -d, already gone
from docker ps.

Example interaction

$ docker ps -a
CONTAINER ID   IMAGE              COMMAND      STATUS                      NAMES
a9f17c4e8b30   ingest-worker:2.0  "/start.sh"  Exited (0) 14 seconds ago   worker

$ docker logs worker
[boot] ingest-worker 2.0 starting
...
[boot] launching worker process in the background
[boot] worker started (pid 23)
[boot] startup complete

Exit code 0 (a clean exit), and the logs say startup completed — yet the container is stopped.

Acceptance

You've solved it when:

  • You've shown the container Exited (0) — a clean exit, not a crash
(docker ps -a; docker inspect workerState.ExitCode 0, Running false) — and explained that a container runs only as long as its PID 1 (the entrypoint). The entrypoint launched the worker in the background (worker &) and returned, so PID 1 exited 0 and Docker stopped the container. NOT misdiagnosed as a crash, an OOM kill, or a missing image (exit 0, logs say "startup complete").
  • You've stated the fix: keep the real process in the foreground as
PID 1 — exec it (exec python worker.py), drop the trailing &, or use the app's foreground flag (e.g. nginx -g 'daemon off;') — so the container stays up.

Constraints

  • Tools: docker CLI only.
  • The exit code is 0 — don't chase a crash, an OOM kill, or a bad image.
The logs show a normal, complete startup.
  • docker restart worker does NOT help — it runs the same daemonizing
entrypoint and exits 0 again. The fix is in how the entrypoint runs the process, not in restarting it.

Follow-up

  1. Why does a container stop the instant PID 1 exits, even when a child
process it spawned is still running inside?
  1. How would exec-ing the worker (exec python worker.py) instead of
backgrounding it keep the container alive — and why does it also fix signal handling (docker stop)?
  1. Why do nginx and redis-server --daemonize yes hit this same trap, and
what's the foreground form of each?
Live session
Code
SavedNo commands yet