Sub topic 3
BuildKit and Buildx
This chapter assumes you can write a Dockerfile, run docker build, and push to a registry. It also assumes you know a container image is tied to a CPU architecture, which earlier chapters covered. Here you learn which tools do the building and how to check that your setup has them.
BuildKit: the build engine
BuildKit is the engine that turns a Dockerfile into an image. It runs as a daemon called buildkitd. Docker Engine has used BuildKit by default for docker build since version 23.0.
BuildKit differs from the old builder in several ways that matter here:
- It converts the Dockerfile into a graph of build steps. Independent stages run in parallel, and stages that the final image doesn't need are skipped.
- It caches each step by content, and the cache can be exported and imported.
- It can build the same Dockerfile for several platforms in one request.
- It can send the result to different destinations, called exporters: the local image store, a tarball, or a registry.
The last two points are what multi-platform builds depend on.
Buildx: the client
Buildx is a Docker CLI plugin. It adds the docker buildx command, which sends build requests to a BuildKit daemon. Buildx also manages builders, which are the BuildKit instances it talks to. Compared with plain docker build, docker buildx build accepts options such as --platform, --push, and --cache-to.
The next chapter covers builders and drivers in detail. For now, remember the split: Buildx is the client, BuildKit is the server.
Checking your setup
Confirm that Buildx is installed:
docker buildx versionList the builders Buildx knows about:
docker buildx lsOn a fresh Docker installation you normally see one builder named default. It uses the docker driver, which runs BuildKit inside the Docker Engine itself. Inspect it to see what it supports:
docker buildx inspectThe output includes the driver, the node status, and a Platforms: line. With the docker driver, this line usually lists only the host's own platform and any platforms already registered for emulation.
Why the default builder is not enough
The default builder is convenient for single-platform builds, but it has a limit. With the classic image store, the Docker Engine can hold only one platform's image per tag. It cannot store a manifest list locally. If you ask it for several platforms, the build fails with an error like this:
ERROR: Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.You have two ways out:
- Create a builder with a different driver, such as
docker-container. It runs BuildKit in its own container and can export a manifest list straight to a registry. The tutorial uses this approach. - Turn on the containerd image store in Docker Engine. The engine can then keep multi-platform images locally.
Pushing with --push skips the local store entirely, so a docker-container builder works without changing the engine.
Common errors
| Symptom | Likely cause |
|---|---|
| `docker: 'buildx' is not a docker command` | The Buildx plugin is not installed. |
| `Multi-platform build is not supported for the docker driver` | The active builder uses the `docker` driver. |
| `Platforms:` shows only one entry | Emulation is not set up yet. A later chapter covers it. |
Exercise
You run docker buildx build --platform linux/amd64,linux/arm64 . on a fresh Docker installation and get an error about the docker driver. Which component is the client, which is the server, and what is the smallest change that lets the build proceed?
Show answer
Buildx is the client and BuildKit (buildkitd) is the server. The default builder uses the docker driver, which cannot produce a multi-platform result locally. Create and select a builder with the docker-container driver (docker buildx create --name multi --driver docker-container --use) and push the result with --push.