Advanced
Searching inHow-to guides
How to search
  • Type the task in your own words (find port, open firewall, disk full) or paste an error message in quotes.
  • Choose "Quick answer" to see only the commands, or an area to stay in one field.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

How-to 141Containers · Docker

How to build images for ARM and x86 with buildx

Your laptop is an Apple Silicon Mac (ARM), production runs on x86 servers, and the cloud now offers cheaper ARM instances (AWS Graviton, Azure Cobalt). An image built for one CPU type fails on the other with exec format error. docker buildx builds one image for both platforms and pushes them under one tag — each machine pulls its own variant. This how-to sets it up and checks the result.

  • 5 Lessons
  • 2 Commands

$ run as a normal user# run as root (or with sudo)

141.1

The quick answer

docker buildx create --name multi --use
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64,linux/arm64 -t registry.example.com/shop/api:1.4.2 --push .
docker buildx imagetools inspect registry.example.com/shop/api:1.4.2

The result is a manifest list: one tag, two images (amd64 + arm64).

141.2

Step by step

  1. A builder that can build several platforms — the docker-container driver (quick answer). On an x86 machine, building ARM uses QEMU emulation; install it once if inspect does not list linux/arm64:
docker run --privileged --rm tonistiigi/binfmt --install arm64
  1. Build and push (quick answer). Multi-platform images must be pushed (or exported) — the local Docker image store can not hold a list by default.
  2. Make the Dockerfile platform-aware — base images must exist for both (official images do), and downloads must pick the right binary:
Dockerfile (part)
FROM --platform=$BUILDPLATFORM golang:1.24 AS build
ARG TARGETOS TARGETARCH
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/api ./cmd/api
 
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/api /api
ENTRYPOINT ["/api"]

Cross-compiling (--platform=$BUILDPLATFORM for the build stage) is much faster than emulating the whole build.

  1. Check what was pushed:
docker buildx imagetools inspect registry.example.com/shop/api:1.4.2
Manifests:
  Name:      registry.example.com/shop/api:1.4.2@sha256:9b1c…
  Platform:  linux/amd64
  Name:      registry.example.com/shop/api:1.4.2@sha256:3e7a…
  Platform:  linux/arm64
  1. Speed up with a cache in CI:
docker buildx build --platform linux/amd64,linux/arm64 --cache-from type=registry,ref=registry.example.com/shop/api:buildcache --cache-to type=registry,ref=registry.example.com/shop/api:buildcache,mode=max -t registry.example.com/shop/api:1.4.2 --push .
  1. Test one platform locally:
docker run --rm --platform linux/arm64 registry.example.com/shop/api:1.4.2 --version

141.3

Check that it worked

imagetools inspect lists both linux/amd64 and linux/arm64, and the same tag runs on an x86 server and an ARM node without exec format error.

141.4

Common problems

ProblemCauseFix
exec format errorImage built for the other CPU.Build multi-platform; check with imagetools inspect.
multiple platforms feature is currently not supported for docker driverDefault builder.docker buildx create --use (docker-container driver).
ARM build is very slowFull emulation with QEMU.Cross-compile in the build stage, or use native ARM runners.
no match for platform in manifestA base image has no ARM variant.Choose a base image that supports both.
Image not in docker images after buildMulti-platform result was pushed, not loaded.Use --load with one platform for local tests.
Downloaded binary is x86 inside the ARM imageHard-coded download URL.Use TARGETARCH in the URL.

141.5

Go further

1What does a multi-platform image look like in the registry?

One tag pointing to a manifest list with one image per platform (for example amd64 and arm64).

2Why cross-compile in the build stage instead of emulating?

The build runs natively and only the target binary is for ARM — much faster than QEMU emulation.

All commands in this chapter