Junior — Middle
Why does the first started container in Docker receive a process ID of 1?
sobes.tech AI
Answer from AI
In Docker, the first started container receives PID 1 because inside the container, the process runs in an isolated process namespace (PID namespace). In this namespace, the first process started always gets the process identifier 1, similar to how in a regular system, PID 1 is the init process.
PID 1 in the container acts as the init process: it is the parent process for all other processes inside the container. This is important because PID 1 handles signals and manages the lifecycle of child processes.
Thus, Docker creates an isolated process space for the container, and the first process inside it gets PID 1, regardless of the PID in the host system.