#pid-1-die
What happens if PID 1 dies in a Docker container?
Что отвечать
The container exits immediately. PID 1 is special in Linux. When it dies, the kernel sends SIGKILL to every other process in that PID namespace, and the namespace is torn down. On the host, a dead PID 1 (usually systemd) is a kernel panic.
Что хотят услышать
A senior should: - separate PID 1 on the host from PID 1 in a container's namespace - name the duties of PID 1: reaping zombies and handling SIGTERM - mention `tini` and `dumb-init` and the `docker run --init` flag - explain why `bash` as PID 1 is a bad idea (by default it does not react to SIGTERM and does not reap zombies)
Подводные камни
- ✗ Saying 'the system will panic' without the namespace caveat. That only happens for the host's PID 1.
- ✗ Forgetting that PID 1 must call wait() for orphaned children, otherwise they become zombies.
- ✗ Believing node, python, or java as the ENTRYPOINT works correctly as PID 1. Most runtimes have no built-in reaper.
Follow-up
- ? What is tini for, and why did Docker make `--init` a separate flag instead of the default?
- ? What happens if PID 1 ignores SIGTERM but `docker stop` sends it?
- ? How does Kubernetes tell a clean pod exit apart from a PID 1 crash?
Глубина в базе знаний