Docker
Docker is a tool for packaging an application together with everything it needs to run (its code, runtime, libraries and config) into an image, and then 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 server, which is the whole point.
A few properties make it worth understanding properly:
- Images are immutable and layered: An image is a stack of read-only filesystem layers, each identified by the hash of its contents. Two images built on the same base share those layers on disk and over the network.
- Containers are processes, not machines: A container is an ordinary Linux process that the kernel has been told to show a restricted view of the system. There's no guest operating system and no hypervisor, so a container starts in well under a second and costs little more than the process itself.
- Isolation comes from the kernel: Namespaces decide what a container can see, and cgroups decide how much CPU and memory it can use. Every container on a host shares that host's kernel.
- Portability through a standard format: Docker images follow the Open Container Initiative (OCI) spec, so the image you build with Docker runs unchanged on Kubernetes, AWS ECS, Cloud Run or Lambda.
Nobody will ask you to design Docker in a product interview. But containers sit underneath almost every modern deployment, and they come up directly in questions about CI/CD, online judges and code sandboxes, serverless platforms, and container orchestrators. When you say "we'll run user code in a container," a good interviewer will ask what that actually protects you from. So we'll cover how images and containers work, what isolation they really give you, and how to talk about them in a design.
Images and Layers
An image is built from a Dockerfile, a short script of build steps:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
USER 1000
CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:server"]
Each instruction that changes the filesystem (COPY, RUN, ADD) produces a new layer: a tarball of the files that step added, changed or deleted. The image is the ordered list of those layers plus a small JSON config (environment variables, the default command, the user to run as). A manifest ties them together by listing each layer's digest.
Everything is content-addressed. A layer's ID is the SHA-256 hash of its bytes, so the same layer is stored once no matter how many images reference it. If 200 services on a host all start FROM python:3.12-slim, the base layers are downloaded and stored once.
Build Caching
When you rebuild, Docker reuses a cached layer if the instruction and its inputs haven't changed. Once one step misses the cache, every step after it reruns. That's why the Dockerfile above copies requirements.txt and installs dependencies before copying the rest of the source. Changing one line of application code invalidates only the last COPY, and the slow pip install layer comes from cache. Reverse the order and every commit reinstalls every dependency.
Multi-stage builds keep build tools out of the final image:
FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /out/server ./cmd/server
FROM gcr.io/distroless/static
COPY --from=build /out/server /server
ENTRYPOINT ["/server"]
The first stage has the full Go toolchain (hundreds of MB). The final image has only the static binary on a minimal base, often tens of MB in total. Smaller images pull faster, start faster and contain fewer packages with known vulnerabilities.
Tags and Digests
A tag like orders:1.42.0 or orders:latest is a mutable pointer to a manifest. A digest like orders@sha256:9f86d0... is the hash of the manifest itself and can never point anywhere else. Production deploys should pin digests (or at least immutable version tags), so that "roll back to what we ran yesterday" means exactly the same bytes. Deploying latest is a common way to end up with two replicas of the "same" service running different code.
Registries
Images live in a registry: Docker Hub, Amazon ECR, Google Artifact Registry, GitHub Container Registry, or a self-hosted one like Harbor. The registry is essentially a blob store keyed by digest, plus a small index of tags. docker push uploads only the layers the registry doesn't already have, and docker pull downloads only the layers the host doesn't already have.
If you're designing a CI/CD system or a deployment platform, the registry is a real component in your diagram, not a detail. Builds push to it, every node pulls from it, and when a deploy rolls out to 2,000 hosts at once, it becomes a hot spot. That's where caching pull-through mirrors and peer-to-peer distribution come in (more below).