ReferencesThe Container Runtime
Docker
The packaging format almost every service now ships in.
Docker at a glance
- A Dockerfile — a declarative recipe for an image.
- BuildKit, the default builder since the legacy path was deprecated.
- Buildx — builders that can run as a container, in Kubernetes, or on a remote daemon.
- Layer caching — only the layers that changed are rebuilt.
- OCI images — the format Docker images are written in, and the one other runtimes read.
What it is
An image is a filesystem plus the metadata needed to run it. A container is that filesystem mounted, with a process started inside it and a handful of kernel features — namespaces, cgroups, capability dropping — keeping it from touching anything it should not.
The value was never the packaging format on its own. It was that the packaging format became a contract: the thing that runs in CI is the thing that runs in production, byte for byte.
How it works
A build is a sequence of layers, each one a diff. The cache is the diff chain, so a build only re-runs the steps after the last thing that changed. BuildKit parallelised that, added better cache control, and made the build itself able to run somewhere other than your machine.
- BuildKit is the default builder for Docker Desktop and Docker Engine; `docker build` uses Buildx unless you are in Windows container mode or set `DOCKER_BUILDKIT=0`.
- With BuildKit only the files your build actually uses are transmitted, and leading `../` paths are stripped rather than followed.
- Buildx exposes four drivers: `docker` (the bundled library), `docker-container`, `kubernetes`, and `remote`.
- Windows container support is the one place the legacy builder is still used, because BuildKit's Windows support is still experimental.
Under the hood
| Piece | What it is |
|---|---|
| Builder | BuildKit — the default; the legacy builder is deprecated |
| Driver | Buildx — docker, docker-container, kubernetes, remote |
| Image format | OCI — read by Docker, containerd and other runtimes |
| Isolation | Namespaces, cgroups and dropped capabilities |
| Caching | Per-layer; only the steps after the last change re-run |