Docker Engine (Part 1)
Understanding Docker Architecture: From Monolith to Modular Engine
When you run a command like docker run nginx, a lot happens behind the scenes before that container actually starts. Understanding Docker's internal architecture—and how it evolved from a single monolithic tool into a modular, industry-standard ecosystem—will make you much better at debugging, securing, and optimizing containerized workloads.
1. The Core Components of the Docker Engine
First released to the public in 2013, Docker is built on a client-server architecture. When people talk about "Docker," they are usually referring to the Docker Engine, which consists of three main components:
- Docker CLI (Client): The command-line interface (
docker) where you type commands likedocker build,docker pull, ordocker run. The CLI doesn't actually build or run anything itself; it simply translates your commands into API requests. - REST API: The communication bridge between the CLI (or any external tool) and the Docker daemon. It exposes endpoints over a UNIX socket (locally) or a network interface (remotely) to manage Docker objects.
- Docker Daemon (
dockerd): The background server process running on the host machine. It listens for REST API requests and is responsible for orchestrating Docker objects—images, containers, networks, and storage volumes.
2. Under the Hood: How Containers Actually Run
Docker doesn't invent containerization from scratch; it relies on core features built into the Linux kernel:
- Namespaces: Isolate what a process can see (process IDs, network interfaces, file systems, hostnames).
- Control Groups (cgroups): Limit and meter how much hardware resources (CPU, memory, disk I/O) a process can use.
From LXC to libcontainer
In its earliest versions, Docker relied on LXC (Linux Containers) to interact with kernel namespaces and cgroups. While LXC worked, working with it directly was complex, and relying on an external dependency made it harder for Docker to innovate across different Linux distributions.
With the release of Docker 0.9, Docker introduced libcontainer. Written in Go (the same language as Docker itself), libcontainer allowed Docker to communicate directly with Linux kernel APIs without needing LXC in the middle. It quickly became Docker's default execution environment.
3. The Open Container Initiative (OCI)
Until early 2015, the container ecosystem lacked universal standards. Every container tool had its own image format and runtime behavior, creating a risk of fragmentation and vendor lock-in.
To solve this, Docker, CoreOS, and other industry leaders formed the Open Container Initiative (OCI) under the Linux Foundation. The OCI established two foundational open standards:
Specification | Purpose |
Runtime Specification ( | Defines how to run a filesystem bundle unpacked on disk. It standardizes lifecycle commands ( |
Image Specification ( | Defines how container images are structured, layered, and packaged so that an image built by one tool can be run by any compliant engine. |
4. Refactoring the Monolith: containerd, runC, and shim
Originally, the Docker daemon (dockerd) was a massive monolithic codebase. It handled everything: image builds, networking, volumes, API requests, and the low-level execution of every container. If you needed to upgrade or restart dockerd, every running container on the host would stop too.
Starting in Docker 1.11, Docker broke this monolith apart into smaller, modular, OCI-compliant components:
- runC (The Low-Level Runtime) Docker extracted the container-execution logic (built on libcontainer) into a standalone command-line tool called runC and donated it to the OCI.
runC has one job: take a container configuration, talk to the Linux kernel (namespaces/cgroups) to spawn the container process, and then exit.
Because runC is standalone, you can actually run OCI containers using only runC without installing Docker at all—though you would miss out on Docker's networking, image management, and developer UX.
- containerd (The High-Level Runtime) To manage the lifecycle of multiple runC containers, Docker spun off containerd (pronounced container-dee).
containerd handles image pulling/pushing, storage, and supervising container execution by calling runC.
Later donated to the Cloud Native Computing Foundation (CNCF), containerd is now the standard container runtime used under the hood by Kubernetes as well.
- containerd-shim (Daemonless Containers) This answers a critical production question: What happens to running containers if dockerd or containerd crashes or restarts for an upgrade?
When containerd asks runC to start a container, it does so through a lightweight process called containerd-shim:
containerd starts containerd-shim.
containerd-shim invokes runC to create and start the container.
Once the container is running, runC exits immediately so it doesn't waste memory sitting idle.
containerd-shim stays alive as the parent process of the container.
Because containerd-shim holds open the container's standard I/O streams (STDIN, STDOUT, STDERR) and reports its exit status back up the chain, containers remain completely decoupled from the Docker daemon. You can restart or upgrade dockerd without dropping a single live container.
5. Putting It All Together: The Execution Flow
When you execute docker run -d nginx, the request flows down through each layer of the modern Docker architecture:
- Docker CLI sends a
POSTrequest to the Docker REST API. dockerd(Docker Daemon) receives the request, sets up networking/volumes, and passes container creation instructions tocontainerdvia gRPC.containerdpulls thenginximage (if not cached locally) and spawns acontainerd-shimprocess.containerd-shiminvokesrunCwith the unpacked image bundle and configuration.runCinterfaces with the Linux Kernel (vialibcontainer) to set up namespaces and cgroups, starts thenginxprocess, and then exits.containerd-shimtakes ownership of the runningnginxcontainer until it stops.
Summary
Docker's architecture evolved from an LXC wrapper into a clean, layered stack:
dockerdhandles developer experience, builds, volumes, and networking.containerdmanages image transfers and container lifecycles.containerd-shimkeeps containers running even if the daemon restarts.runCtalks directly to the Linux kernel to execute OCI-compliant containers.
Understanding this separation of concerns makes it clear why Kubernetes can use containerd directly without needing the full Docker Engine, and why modern container infrastructure is so resilient in production.
Comments
Join the discussionNo comments yet. Be the first to comment.