Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 134/ 160
07. CI/CD, Registries & Production Operations

The PID 1 Problem & Using Init Systems (tini, --init)

Fix zombie reaping and signal forwarding with tini or docker --init.

IntermediatePID 1 · tini3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Use an init when the process tree needs signal forwarding and orphan reaping, or adopt an exec-form entrypoint application that deliberately handles both.

Think of it like…

PID 1 is the daycare supervisor: if it stops collecting finished children and passes dismissal notices incorrectly, the room fills and no one hears closing time.

Where you’ve seen it

In practice, docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"] is the concrete move for this job: fix zombie reaping and signal forwarding with tini or docker --init. The release is not accepted until start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker confirms the result.

Words you’ll hear

PID 1
The implementation control in docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"] for fix zombie reaping and signal forwarding with tini or docker --init.
tini
The result to observe with start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker, rather than infer from a successful command alone.
--init
The production boundary exposed when adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.

Visual diagram

Loading interactive diagram

Theory & deep dive

PID 1 control path

The concrete mechanism is docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]. The observable result is start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker; if those disagree, inspect the runtime evidence before changing unrelated settings.

Fix zombie reaping and signal forwarding with tini or docker --init. Keep PID 1, tini and --init in the same deployment record so the intent and the observed state cannot drift apart.

Concrete PID 1 setup

docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]

Key takeaway: Prove tini with start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker, not with command success alone.

--init failure boundary

Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child. The narrow failure to design for is adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.

Accept this compromise explicitly: Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity. The controlled check-start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.

Key takeaway: Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child.

Use an init when the process tree needs signal forwarding and orphan reaping, or adopt an exec-form entrypoint application that deliberately handles both.
Key numbers at this step
Intent
PID 1

When to use it & trade-offs

What it is

PID 1 in Linux has special signal and child-reaping semantics. A non-init application as PID 1 can ignore forwarded/default signals and fail to reap orphaned grandchildren; tini is a tiny init that forwards signals and reaps zombies, and Docker --init wires it into container startup.

Why it matters: Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child.

When to reach for it

  • The fit is strongest for this job: fix zombie reaping and signal forwarding with tini or docker --init. Pair it with start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker in the runbook.
  • Production PID 1 changes should make tini observable through docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"], rather than trusting the runtime default.
  • Keep a rollback example for the case where adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.

When to avoid or be careful

  • Do not accept command success while the system can still fail by adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.
  • Avoid erasing --init protection merely to dodge this cost: “Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity”.
  • Do not replace the evidence path-start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker-with a screenshot or a mutable tag.

docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]: practical choices

Explicit PID 1
Best for: Fix zombie reaping and signal forwarding with tini or docker --init, with a reviewed runbook.

Strengths: PID 1 in Linux has special signal and child-reaping semantics. A non-init application as PID 1 can ignore forwarded/default signals and fail to reap orphaned grandchildren; tini is a tiny init that forwards signals and reaps zombies, and Docker --init wires it into container startup.

Watch out: Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity.

Ambient default
Best for: Short-lived tini experiments with low blast radius.

Strengths: It can begin with docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"] and fewer surrounding controls.

Watch out: It silently accepts adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction, which makes the result hard to reproduce after promotion.

Managed --init
Best for: Teams that centralize --init policy across many workloads.

Strengths: Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child.

Watch out: The platform adds an ownership and debugging layer; retain start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]
  • start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker
  • Failure signature: adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction
  • Trade-off: Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity.

Benchmarks & rules of thumb

1 PID -
tini becomes container PID 1
0 zombie accumulation -
required after a reaping test
SIGTERM + SIGINT -
must reach the real service process

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"] as proof and skipping start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker.
  • Adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction
  • Optimizing PID 1 without accepting that docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity.

Likely interviewer follow-ups

  • Why does docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"] address PID 1 here rather than through application code?
  • How would you distinguish healthy tini from the failure “adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction” using start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker?
  • When would this trade-off-“Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity”-justify a different --init design?
Interview tip: Give one concrete operation-docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]-and one proof-start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker. Then name the boundary: adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply The PID 1 Problem & Using Init Systems (tini, --init) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Graceful Shutdowns, SIGTERM vs SIGKILL & Signal Handling
Next topic
Zero-Downtime Container Deployments & Blue-Green Switching