You open your terminal, type docker run nginx, press Enter, and within milliseconds, a fully functional web server is up and running. To most developers, it feels like magic.
But under the hood, Docker is orchestrating a well-structured pipeline of daemons, container runtimes, and low-level Linux kernel features to isolate and launch your application.
Whether you are preparing for a DevOps interview, debugging production containers, or just want to understand the tools you use every day, this guide breaks down the entire internal lifecycle of a Docker container—from the moment you hit Enter to the second your application starts.
(Insert your diagram: Inside Docker: The Complete Container Lifecycle)
Stage 1: The User & Control Plane (Command to API)
Everything begins at your terminal, where user intent is translated into a machine-readable API request.
1. You Run a Command
When you execute a command like docker run nginx, you are instructing Docker to create and start a new isolated environment using the official Nginx image.
2. Docker CLI
The Docker CLI (docker) is purely a command-line client. It does not actually build images or run containers itself. Instead, it parses your command-line flags and translates them into a standardized REST API request, which it sends to the Docker Daemon (typically over a local Unix socket /var/run/docker.sock or a TCP port).
Stage 2: The Docker Engine & Runtime Management
Once the REST API request arrives, Docker's background services take over to prepare the environment and manage the container's state.
3. Docker Daemon (dockerd)
The Docker Daemon (dockerd) is the persistent background process that listens for Docker API requests. When it receives your request to run nginx:
- It checks your local cache to see if the nginx image already exists on your machine.
- If the image is missing, dockerd pulls the required image layers from a container registry (like Docker Hub).
- Once the image is ready, dockerd delegates the actual container lifecycle execution to containerd.
4. containerd
Originally separated out from the monolithic Docker Engine, containerd is an industry-standard, high-level container runtime. It manages the complete lifecycle of a container on its host system—including image transfer, storage, container execution, supervision, and low-level networking attachments. When told to start a container, containerd does not create the process directly; it hands off that job to containerd-shim and runc.
Stage 3: The Shim & Low-Level Container Creation
This is the bridge between Docker's high-level management tools and the underlying operating system.
5. containerd-shim & runc
- runc: This is a lightweight, low-level OCI (Open Container Initiative) runtime. Its sole job is to interface directly with the Linux kernel to spawn the container process. Once runc creates and starts the container, runc exits immediately.
- containerd-shim: Because runc exits after starting the container, containerd-shim stays behind as the parent process of the container. It acts as a critical middleman that keeps standard I/O streams (STDIN, STDOUT, STDERR) open, reports the container's exit status back to containerd, and allows you to restart or upgrade the main Docker Daemon without killing your running containers.
Stage 4: Linux Kernel – Isolation & Control
A common misconception is that containers are lightweight virtual machines. In reality, a container is simply an isolated Linux process. runc configures four core Linux kernel primitives to create the illusion of an independent machine:
| Kernel Feature | Role in Docker | What It Does |
|---|---|---|
| Namespaces | Isolation | Wraps global system resources so the container gets its own isolated view of process IDs (PID), network interfaces (NET), mount points (MNT), hostnames (UTS), and user IDs (USER). Inside the container, your app thinks it is PID 1. |
| Cgroups (Control Groups) | Resource Limiting | Governs and limits how much hardware resources—CPU, memory, disk I/O, and network bandwidth—a single container can consume, preventing one noisy container from crashing the host server. |
| OverlayFS | Layered Filesystem | Combines multiple read-only image layers with a thin, writable container layer on top (Copy-on-Write). This makes starting containers fast and saves massive amounts of disk space. |
| Networking (veth, bridge, NAT) | Connectivity | Creates a virtual Ethernet pair (veth), attaches one end to the container's network namespace and the other to Docker's virtual bridge (docker0), and configures Network Address Translation (NAT) so the container can communicate externally. |
Stage 5: Container Created & Application Starts
With all kernel boundaries locked in place, the lifecycle reaches its final execution phase:
- Container Created: All namespaces, cgroups, storage mounts, and virtual network interfaces are initialized. A lightweight, isolated runtime environment is now ready.
- Application Starts: The container's default entrypoint or command (such as starting the Nginx web server or a Node.js app) executes as the primary process (PID 1) inside the isolated environment.
Quick Recap: The Docker Execution Chain
Whenever you run a container, data and control flow through this sequence:
[ \text{Docker CLI} \xrightarrow{\text{REST API}} \text{dockerd} \longrightarrow \text{containerd} \longrightarrow \text{containerd-shim + runc} \longrightarrow \text{Linux Kernel} \longrightarrow \text{Running App} ]
Understanding this internal architecture makes troubleshooting much easier. If an image fails to download, you look at dockerd. If a container runs out of memory and gets killed (OOMKilled), you know Cgroups stepped in. If two containers cannot reach each other, you inspect Namespaces and bridge/veth networking.
Frequently Asked Questions (FAQ)
What is the difference between dockerd, containerd, and runc?
dockerd is the high-level engine that handles REST API requests, builds images, and manages volumes/networks. containerd manages the container lifecycle (start, stop, pause), while runc is the low-level runtime that talks directly to the Linux kernel to spawn the container process.
Why does Docker need containerd-shim?
containerd-shim decouples running containers from containerd and dockerd. Because the shim holds onto the container's file descriptors and exit status, the Docker daemon can be restarted or upgraded in production without taking down running containers.
Does Docker work the same way on Windows and macOS?
Because Docker relies directly on Linux Kernel features (Namespaces, Cgroups, OverlayFS), Docker Desktop on Windows and macOS runs a lightweight, hidden Linux virtual machine behind the scenes to host dockerd, containerd, and your containers.



