Containers · Chapter 1 of 4 · 3 min

Why Containers

A container packs an application with everything it needs to run, so it behaves the same on a laptop, in CI and in the cloud. What that means in practice.

The problem containers solve

An application never runs alone. It needs a language runtime of a certain version, system libraries, fonts, configuration, and its own dependencies. On a developer's laptop those are installed one way; on a server, another. The result is the oldest sentence in software: "it works on my machine."

A container solves this by packing the application together with everything it needs, down to the operating-system libraries, into one bundle that runs the same way everywhere a container runtime exists.

Image and container

Two words get mixed up constantly:

The relationship is like a program file and a running program. In this site's pipeline, Cloud Build makes one image per commit, and Cloud Run starts as many containers from it as traffic needs.

Containers are not virtual machines

A virtual machine emulates a whole computer, with its own operating-system kernel. A container shares the host's kernel and isolates only the process, its files and its network. So containers:

The trade-off is weaker isolation than a VM. On a managed platform like Cloud Run, the provider adds its own sandbox underneath, so for a website this is not a concern you manage yourself.

Layers

An image is built in layers, one per instruction in the Dockerfile. Each layer stores only what changed. Layers are cached: if an instruction and everything before it are unchanged, Docker reuses the stored layer instead of running the step again.

This single fact shapes how a good Dockerfile is written, as the next chapter shows: put the things that change rarely (system packages, dependencies) first, and the things that change on every commit (your code) last.

Immutable delivery

The biggest operational benefit is that an image never changes after it is built. The image tagged with commit b5a0d60 will be byte-for-byte the same tomorrow and next year. That gives you:

Where configuration goes

If an image never changes, how does the same image run with different settings? Through environment variables and mounted secrets supplied when the container starts. The image holds the code; the platform supplies the configuration. The Secrets and Security series covers this split in detail.

When you do not need containers

For a static site with no server code, a container adds nothing; a static host is simpler. Containers earn their place when there is a server process with dependencies, as there is here.

Try it yourself

Install Docker Desktop, then run docker run --rm node:22-slim node -e "console.log(process.version)". Docker downloads the official Node image and runs one command in a fresh container that disappears afterwards. That is the entire idea in one line.