$ docker run --rm alpine ps

Containerization

Containerization means packaging an application together with everything it needs to run (interpreter, libraries, system packages, config) into one image, and running that image as an isolated process called a container. The same image runs the same way on a laptop, a CI runner and a production cluster, which ends the “works on my machine” problem.

For data engineers this is daily work: an Airflow task, a Spark driver, a dbt run or a Kafka connector is usually a container image pulled from a registry and started by an orchestrator.

How a container works

A container is not a small virtual machine. It is a normal Linux process that the kernel fences off with two features:

  • Namespaces give the process its own view of the system: its own process IDs, network interfaces, hostname, mount points and users.
  • cgroups cap what it may consume: CPU, memory, I/O. A Spark executor limited to 4 GB is killed by the kernel if it tries to use 5 GB.

The files the process sees come from the image: a stack of read-only, content-addressed layers, plus a thin writable layer per container. See Docker for an animated walk-through.

$ docker run --memory=256m --cpus=0.5 postgres:18
A container is just a Linux process
postgres host PID 4812 a plain process NAMESPACE WITHOUT IT, THE PROCESS SEES WITH IT, THE PROCESS SEES pidall 312 host processes nethost NICs and every port mntthe host's whole disk utshostname host-01 ipchost shared memory userUID 0 is host root pid only its own: postgres is PID 1 net own eth0, IP 172.17.0.2 uts hostname 3f2a9c1d7b4e mnt image layers mounted as / ipc private shared memory user root inside, UID 100000 outside cgroups --memory=256m --cpus=0.5 memory used 180 MB limit 256 MB CPU over 0.5 core: slowed, not killed 300 MB OOM-killed · exit 137 killed by the kernel
  1. Start with an ordinary process on the host. Without any fences it sees every process, every network port, the whole disk and the real hostname.
  2. A pid namespace gives it its own process tree. Inside, postgres is PID 1 and sees no other processes.
  3. A net namespace gives it its own network interface and IP; uts gives it its own hostname (the container ID).
  4. A mnt namespace swaps the filesystem: the image's layers are mounted as /, so the host disk is invisible.
  5. ipc isolates shared memory; a user namespace can map root inside to an unprivileged UID outside. These are the blinders.
  6. cgroups are the budget: at most 256 MB of memory and half a CPU core. Too much CPU only slows it down.
  7. Cross the memory limit and the kernel's OOM killer ends the process. The container exits with code 137.

Try it: docker run --rm alpine ps lists a single process, and docker run --rm alpine hostname prints a random ID. With no --memory or --cpus flags there is no ceiling, so one runaway container can starve the whole machine. --pids-limit caps the number of processes, which stops fork bombs.

Containers vs virtual machines

$ time docker run --rm alpine true
Two ways to isolate the same apps
VIRTUAL MACHINES CONTAINERS hardware hardware hypervisor host OS · one shared Linux kernel guest OSown kernel guest OSown kernel guest OSown kernel container engine (Docker / Podman) 3 kernels to boot, patch and feed RAM 1 kernel, shared by every container App A+ libs App B+ libs App C+ libs App A+ libs App B+ libs App C+ libs size GBs boot ~30 s+ size MBs start under 1 s
  1. Same hardware on both sides. The question is what sits between it and the apps.
  2. VMs run a hypervisor that fakes whole machines. Containers run on the normal host OS and its single Linux kernel.
  3. Every VM boots its own guest OS and kernel. Containers only need a container engine to set up namespaces and cgroups.
  4. The same three apps on top. In a VM each one carries a full OS; in a container it carries only its libraries.
  5. The result: VM images are gigabytes and boot in tens of seconds; container images are megabytes and start like a process.
Virtual machine Container
What is isolated A whole guest OS on virtual hardware A process tree on the host kernel
Kernel One per VM Shared with the host
Start time Tens of seconds (boots an OS) Milliseconds to a second
Typical size GBs Tens to hundreds of MBs
Isolation strength Strong (hypervisor boundary) Weaker (kernel is shared)
Runs Any OS, e.g. Windows on a Linux host Needs a compatible kernel: Linux containers need Linux
Good for Different OSes, hard multi-tenancy Packaging and scaling apps

They are not rivals. On macOS and Windows, Docker Desktop and Podman run your Linux containers inside a small hidden Linux VM, and cloud Kubernetes nodes are VMs that run many containers. When you need VM-grade isolation for untrusted code, sandboxed runtimes such as gVisor or Kata Containers sit between the two.

The standards: OCI

The Open Container Initiative (OCI) defines three specs: the image format, the runtime (how to start a container from an unpacked image) and the distribution API that registries speak. Because of OCI, an image built with Docker runs under Podman, containerd or Kubernetes unchanged, and can be stored in Docker Hub, GitHub Container Registry, Amazon ECR or Harbor.

Layer Examples Who uses it directly
Build and developer CLI Docker, Podman, Buildah You
High-level runtime containerd, CRI-O Docker Engine, Kubernetes
Low-level runtime runc, crun containerd, Podman

What is in this section

  • Docker: the tool that popularized containers. Images, layers, Dockerfiles and Compose.
  • Podman: a daemonless, rootless, Docker-compatible alternative from Red Hat.
  • containerd: the runtime underneath Docker and most Kubernetes clusters.

Once you can run one container, Container Orchestration covers running thousands of them across a cluster.

Common mistakes

  • Treating a container like a server. Do not SSH in and patch it. Change the image and redeploy.
  • Storing data in the container’s writable layer. It disappears with the container. Use volumes or object storage.
  • Running as root inside the image. Add a USER line; a kernel bug plus root in the container is a host compromise.
  • Huge images. Use slim base images and multi-stage builds so CI and node start-up stay fast.

Learning Resources