Docker interview question · Most asked

Why does PID 1 matter in containers, and what problems can it cause?

Summary

The container's main process runs as PID 1, which Linux treats specially: it does not get default signal handlers (signals it does not handle are ignored, so SIGTERM may do nothing), and it is responsible for reaping orphaned child processes, which otherwise become zombies.

Longer Answer

Symptoms: containers take the full stop timeout (10 s in Docker, 30 s grace period in Kubernetes) to stop and are then killed, losing in-flight work; zombie processes accumulate when the app spawns children. Fixes: handle SIGTERM in the application, use the exec form, and run a tiny init when needed (docker run --init, which uses tini, or tini/dumb-init as the entrypoint).

Key Points

  • PID 1 lacks default signal handlers.
  • Must reap zombie processes.
  • Handle SIGTERM; exec form.
  • --init / tini for reaping and forwarding.

More most-asked Docker questions

← All Docker questions