Sub topic 7
Building a multi-platform image with emulation
This chapter assumes you have a docker-container builder and QEMU handlers registered through binfmt_misc. Both are set up in the previous chapters. You should also be able to write a simple Dockerfile.
What happens during an emulated build
When you pass several platforms to --platform, BuildKit runs one build per platform inside the same builder. The Dockerfile is the same for each platform, but BuildKit resolves a different base image for each one.
Suppose the host is linux/amd64 and you target linux/arm64. BuildKit pulls the arm64 base image. Each RUN step then executes arm64 binaries. The kernel sees a foreign executable, finds its binfmt_misc entry, and hands it to the QEMU user-mode interpreter. The Dockerfile needs no changes for this.
A Dockerfile that shows the architecture
Use a small Dockerfile that prints the architecture it runs on, so you can see the emulation working.
FROM alpine:3.20
RUN uname -m
CMD ["uname", "-m"]Build it for both platforms and print the full log:
docker buildx build \
--platform linux/amd64,linux/arm64 \
--progress=plain .In the log, the RUN uname -m step appears twice. On an amd64 host, one step prints x86_64 and the other prints aarch64. The aarch64 line proves the step ran under emulation.
Getting the result out of the builder
A multi-platform build produces several images. The classic local image store holds one image per tag, so it cannot hold them all. Your options are:
--pushsends the result to a registry as a manifest list. The next chapter covers this.--output type=oci,dest=app.tarwrites an OCI archive containing every platform.--loadworks for one platform only.
To run a single emulated image locally, build one platform and load it:
docker buildx build --platform linux/arm64 -t demo:arm64 --load .
docker run --rm --platform linux/arm64 demo:arm64The container prints aarch64, even on an amd64 machine.
Common errors
| Symptom | Likely cause |
|---|---|
| `exec format error` during a `RUN` step | The QEMU handler for that architecture is not registered. Re-run the binfmt installer. |
| Error about multiple platforms not being supported | You used `--load` with several platforms, or the builder uses the plain `docker` driver. |
| Build works for amd64 but hangs or crashes for arm64 | The tool being run is unstable under QEMU. Compilers and JIT runtimes are typical cases. |
Exercise
You run docker buildx build --platform linux/amd64,linux/arm64 -t app:dev --load . on an amd64 host. The build fails at the end. Why, and what are two ways to fix it?
Show answer
--load cannot import a multi-platform result into the classic local image store. Either add --push and send the result to a registry, or build one platform at a time with --load. You can also write an OCI archive with --output type=oci,dest=app.tar.