Sub topic 4
Builders and drivers
This chapter assumes you can run docker build, write a simple Dockerfile, and push to a registry. It explains what a Buildx builder is and why the default one often cannot build for several platforms.
What a builder is
A builder is a named BuildKit instance that Buildx talks to. Buildx is the command-line client. BuildKit is the engine that runs your build. One machine can have several builders, and exactly one is selected at a time.
Each builder has one or more nodes. A node is a single BuildKit daemon, running locally or on another host. Most builders have one node. A builder with several nodes can send each platform's build to a different machine, which later chapters use for native builds.
List your builders and see which is selected:
docker buildx lsThe selected builder has an asterisk after its name. Almost every installation starts with a builder named default.
Drivers decide where BuildKit runs
A driver is the part of a builder that decides how BuildKit is started and where it runs. You pick the driver when you create the builder.
| Driver | Where BuildKit runs | Multi-platform in one build | Notes |
|---|---|---|---|
| `docker` | Inside the Docker daemon | Only with the containerd image store | Used by the `default` builder. |
| `docker-container` | In a dedicated container | Yes | Supports cache export and multi-node builders. |
| `kubernetes` | In pods on a cluster | Yes | Useful when builds should run on cluster nodes. |
| `remote` | On an existing BuildKit daemon you point to | Yes | You manage the daemon yourself. |
The docker driver is convenient because it needs no setup. Its limits are why this tutorial uses docker-container. On an installation that uses the classic image store, it cannot produce a multi-platform result in one build. It also cannot export a build cache to a registry.
Create and start a builder
Create a builder with the docker-container driver and make it the current one:
docker buildx create --name multi --driver docker-container --use
docker buildx inspect --bootstrap--name labels the builder. --use selects it for later builds. inspect --bootstrap starts the BuildKit container now instead of at the first build. It also prints the driver, the node list, and the platforms each node supports.
Check the Platforms: line in the output. It lists what this node can build. On a plain amd64 host you will usually see linux/amd64 and a few 32-bit variants. Adding linux/arm64 to that list is the job of the next chapter, which covers QEMU.
Switching and cleaning up
Select a different builder with docker buildx use <name>. Remove one with docker buildx rm <name>. Removing a docker-container builder deletes its BuildKit container, and the build cache stored in that container goes with it.
Common errors
- "Multi-platform build is not supported for the docker driver": the selected builder uses the
dockerdriver. Rundocker buildx use multi, or create adocker-containerbuilder. - Builds still use the old builder: you created a builder without
--use. Rundocker buildx lsand select the right one. - A platform is missing from
Platforms:: the node does not support it yet. Emulation or a native node must provide it.
Exercise
You run docker buildx build --platform linux/amd64,linux/arm64 --push . and Buildx reports that multi-platform builds are not supported for the docker driver. Which commands fix this, and why?
Show answer
The selected builder uses the docker driver. Create a builder with the docker-container driver and select it: docker buildx create --name multi --driver docker-container --use, then docker buildx inspect --bootstrap to start it. That driver runs BuildKit in its own container and can build several platforms in one build.