Docker Engine vs Docker Runtime
Purpose, Design, Internals — With cgroups & namespaces explained in context
📑 Table of Contents
What Is Docker?
High-Level Docker Architecture
Docker Engine: Purpose, Components & Design
Docker Runtime: containerd, runc, and the OCI
How Docker Uses cgroups & Namespaces
Docker Lifecycle Internals
Hands-On Commands to Trace Execution
FAANG-Level Interview Q&A
Visual Diagram & Cheat Sheet
🐳 1. What Is Docker?
Docker is an open-source platform that enables:
Building images from code and dependencies
Running containers from images
Managing the lifecycle of containers (start, stop, restart, remove)
Resource isolation using Linux primitives
🧱 2. High-Level Docker Architecture
⚙️ 3. Docker Engine
✅ What is Docker Engine?
The Docker Engine is the core daemon (dockerd) that manages the complete lifecycle of containers, from building images to managing running instances.
🧩 Components of Docker Engine:
🛠️ 4. Docker Runtime
✅ What is Docker Runtime?
The Docker Runtime is the lower-level component responsible for executing containers. Docker uses a layered runtime architecture:
🧱 Breakdown:
🔁 Flow: From CLI to Kernel
docker run nginx
docker CLI sends command to dockerd
dockerd uses containerd to manage container
containerd calls runc (OCI runtime)
runc:
Uses namespaces to isolate the container
Uses cgroups to limit CPU/memory
Starts the container process
Linux kernel enforces all constraints
🧠 5. How Docker Uses cgroups and namespaces
👇 Internally:
When you run:
docker run -it --memory="256m" ubuntu
Docker:
Creates a cgroup under /sys/fs/cgroup/memory/docker/<id>
Sets memory.limit_in_bytes = 256MB
Uses runc to launch process inside namespaces
🔍 6. Docker Lifecycle Internals
🔄 Example: docker run ubuntu
CLI sends REST request to dockerd
dockerd:
Pulls image from registry (if not available)
Creates filesystem from layers (OverlayFS)
Sets up networking (bridge, IP assignment)
Creates cgroups and namespaces
containerd spawns a container task
runc executes the container:
clone() system call with namespace flags
pivot_root() to new root FS
execve() to run the container's init process
🧪 7. Hands-On CLI Tracing
🔎 Trace components
🧪 Show namespaces of a container:
🧪 Show cgroups:
cat /proc/$(docker inspect --format '{{.State.Pid}}' test)/cgroup
🎯 8. FAANG-Level Interview Q&A
❓Q1: What's the difference between Docker Engine and Runtime?
❓Q2: Why is Docker moving to containerd?
containerd is a standalone CRI-compliant runtime
More modular and lightweight
Docker now uses containerd as its runtime backend
❓Q3: Can you run Docker containers without Docker?
Yes, via containerd directly or runc:
ctr image pull docker.io/library/alpine:latest
ctr run -t --rm docker.io/library/alpine:latest demo /bin/sh
Or using runc:
Create a rootfs
Write a config.json
Run: runc run <id>
🧮 9. Visual Diagram
📌 10. Cheat Sheet Summary
✅ Final Takeaway
Docker Engine is the orchestrator;
Docker Runtime (containerd + runc) is the executor.
Together, they use Linux namespaces & cgroups to run secure, resource-controlled containers.
Ref:
https://blog.purestorage.com/purely-educational/containerd-vs-docker-whats-the-difference/
https://www.cloudraft.io/blog/container-runtimes


