Opscraft
Docker · Lesson 1 of 11 · 5 min read

Containers, VMs and the Docker architecture

Docker made containers practical: package an application with its runtime and dependencies into an image, and run it the same way on a laptop, a CI agent, or an EKS node. Most DevOps engineers use it every day; senior interviews go underneath the commands — how images and layers are stored, what a container actually is to the kernel, how BuildKit caching works, how networking is wired with veth pairs and iptables, and how to build images that are small, reproducible and secure enough for a regulated production environment.

What a container really is

A container is an ordinary Linux process started with:

Enlarge diagramONE LINUX HOST, ONE KERNELnginxcontainer 1orders-apicontainer 2postgrescontainer 3sshd, kubelet…normal processesEach box is just processes, seen by ps on the host. Namespaces hide the others; cgroups cap CPU and memory.
Figure 1. Running docker run starts an ordinary Linux process that the kernel fences in with namespaces and limits with cgroups. There is no hidden VM on Linux.
Swipe sideways to see all of it, or tap to open it full screen.
  • Namespaces — its own view of PIDs (it sees itself as PID 1), network interfaces and ports, mounts, hostname, IPC and (optionally) user IDs.
  • cgroups — limits and accounting for CPU, memory, block I/O and number of PIDs.
  • A root filesystem assembled from image layers.
  • Security restrictions: dropped Linux capabilities, a seccomp profile that blocks dangerous syscalls, and AppArmor/SELinux confinement.

Run docker run -d nginx, then ps aux | grep nginx on the host — you'll see the nginx processes. There's no hidden VM on Linux.

Containers vs virtual machines

Containers Virtual machines
Isolation boundary Shared host kernel; namespaces + cgroups Hypervisor; each VM runs its own kernel
Start time Milliseconds to seconds Tens of seconds to minutes
Size MBs (app + libraries) GBs (full OS)
Density Hundreds per host Tens per host
Security Weaker boundary; a kernel exploit can escape Stronger boundary
OS flexibility Must match host kernel type (Linux containers need a Linux kernel) Any OS

They're complementary: on AWS your containers run inside EC2 VMs. Firecracker micro-VMs (used by Fargate and Lambda) combine VM-level isolation with near-container start times. On macOS and Windows, Docker Desktop runs a small Linux VM, which is why bind mounts are slower there.

Enlarge diagramApp AApp BGuest kernelGuest kernelHypervisorHardwareApp AApp BApp Ccontainerd + runcHost kernel (shared)HardwareVirtual machinesContainersstronger isolation · GBs · boots in minuteslighter · MBs · starts in milliseconds
Figure 2. Virtual machines virtualise hardware and each runs its own kernel; containers share the host kernel. On AWS you usually run containers inside EC2 VMs, so you get both.
Swipe sideways to see all of it, or tap to open it full screen.

The engine stack

Enlarge diagramdocker CLIjust a clientdockerdimages, builds,networks,volumescontainerdpulls images,runscontainersshim + runcrunc sets upnamespacesand cgroups,then exitsyour processPID 1 in thecontainerWhoever can reach /var/run/docker.sock controls dockerd, which runs as root: mounting the socket into acontainer hands it root on the host.RESTgRPC
Figure 3. What happens on docker run: the CLI asks dockerd, which asks containerd, which uses runc to create the container. runc exits; a small shim stays with each container.
Swipe sideways to see all of it, or tap to open it full screen.
  • docker CLI — just a client.
  • dockerd — the Docker daemon: images, builds (BuildKit), networks, volumes, the API.
  • containerd — the container runtime daemon (a CNCF graduated project): pulls images, manages snapshots and container lifecycles.
  • containerd-shim — one per container; keeps it running if containerd restarts and holds its stdio.
  • runc — the low-level OCI runtime that actually creates namespaces and cgroups, then execs your process, and exits.

Anyone with access to /var/run/docker.sock controls dockerd — which runs as root — so mounting the socket into a container (a common CI shortcut) hands that container root on the host.

OCI standards and Kubernetes

The Open Container Initiative defines:

  • the image spec (manifest, config, layers),
  • the runtime spec (how runc-like runtimes start a container),
  • the distribution spec (registry API).

That's why an image built by Docker runs unchanged on containerd, CRI-O or Podman. Kubernetes removed dockershim in v1.24 — kubelet talks to containerd directly via the CRI. Your Docker-built images still run fine on EKS; you just can't use docker commands on the node (use crictl instead).

Enlarge diagramdocker buildor buildah, kanikoOCI imagein any registrycontainerdEKS, most KubernetesCRI-OOpenShiftPodmandaemonless
Figure 4. The OCI standards make images portable. Docker builds them; Kubernetes runs them through containerd without Docker at all.
Swipe sideways to see all of it, or tap to open it full screen.