Containerization

Definition

Container

A container is a packaged application (code, interpreter, libraries, configuration) running as an isolated process on a host machine. It uses the host’s resources and operating system kernel, behaves like an isolated machine inside the host, and runs the same way on every host. Containerization is deploying software as containers.

Intuition

Ship the box instead of the laptop

A shipping container separates the product from the transport: the carrier moves the box without knowing what is inside. Software has the same need. Machines differ in CPU architecture, operating system, OS configuration and package versions, so code that works on one machine breaks on another (“it works on my machine”); even print('hello', flush=True) fails on Python 2.7. Instead of shipping your laptop, you ship a container holding exactly the environment the code was tested in.

How it works

  • An image is the package: a read-only, layered file system snapshot (base OS files, runtime, libraries, code) plus metadata such as the default command. A container is a running instance of an image with a thin writable layer; what it writes is lost when it is removed, unless it goes to a mounted volume.
  • Images are built in layers, one per build instruction, cached and shared between images.
  • Isolation comes from Linux kernel features: namespaces limit what a process can see (processes, network, file system, hostname), control groups (cgroups) limit what it can use (CPU, memory).
  • Images are pushed to a registry and run by an orchestrator such as Kubernetes, which schedules them on a pool of machines.

Containers versus virtual machines

Virtual machineContainer
PacksA whole computer, with a guest OSThe app and its dependencies
Runs onA hypervisorThe host OS kernel, via a container engine
WeightHeavy, slow to startLight, starts in seconds
IsolationStrong: separate kernelsWeaker: shared kernel

Key Properties / Variants

  • Same everywhere, within limits. Containers share the host kernel, so Linux images need a Linux kernel (Docker Desktop on macOS and Windows runs a Linux VM underneath), and an image is built for one CPU architecture (arm64 on Apple Silicon, usually amd64 on servers).
  • Isolation is the default and can be opened on purpose: mounted folders, published ports and privileged mode give a container access to the host.
  • One container, one application instance. A system of several services becomes several containers, which Docker Compose or Kubernetes wire together.
  • Reproducibility needs pinned versions. A floating base image tag such as python:3-slim resolves to newer Python over time.

Connections

Appears In