Docker & Containers (50 Qs)•Part 3: Advanced Internals, Scale & Production Security (Senior / Lead)
Debugging Crashing Containers: PID 1 Zombie Reaping and Signal Handling (`tini` / `dumb-init`).
senior LevelCode ExampleSignalsSecurity & AuthDocker & Containers
In Simple Words: In Unix, Process ID 1 (PID 1) has special kernel duties:
- Signal Handling: By default, the Linux kernel ignores
SIGTERMfor PID 1 unless the process explicitly registers a signal handler. If your Node.js or Python app is PID 1 and doesn't handleSIGTERM,docker stophangs for 10 seconds and kills it withSIGKILL, corrupting database transactions! - Zombie Reaping: When child processes terminate, they become zombies until their parent reaps them with
wait(). If the parent process dies, orphaned children are reparented to PID 1. If PID 1 does not reap them, the system exhausts PID limits.
Solution: Minimal Init System (--init or tini)
dockerfile
# Option A: In Dockerfile
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "server.js"]
Or run with docker run --init my-app. tini runs as PID 1, forwards signals properly, and reaps zombie processes.