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:
- An image is the packaged, read-only bundle: a file system plus instructions for how to start. It is built once.
- A container is a running instance of an image, with its own process and a thin writable layer on top. You can start many containers from one image.
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:
- start in seconds or less, not minutes;
- are small: tens or hundreds of megabytes, not gigabytes;
- are cheap enough to throw away and replace instead of repairing.
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:
- Reproducibility: what was tested is exactly what runs.
- Easy rollback: going back means running the previous image, not rebuilding old code and hoping it builds the same way.
- No configuration drift: nobody logs in to a server and edits a file. If something has to change, you build a new image.
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.