Multi-platform Build

Difficulty: Advanced

Question

How do you build a single Docker image tag that runs on both ARM64 (Apple Silicon, AWS Graviton) and AMD64 machines?

Answer

Use BuildKit through docker buildx build --platform linux/amd64,linux/arm64 -t org/app:1.0 --push .. Buildx builds one image per platform and pushes them under a single tag as a manifest list (an OCI image index), so docker pull on a Mac M-series laptop gets the arm64 variant and a CI runner on Intel gets the amd64 variant automatically.

Why one tag can hold many architectures

A normal image manifest points to one config and one set of layers for one OS/architecture. A multi-platform image adds an index on top: a small JSON document listing several manifests, each tagged with platform: {os, architecture, variant}. When the client pulls org/app:1.0, the registry returns the index, the client picks the entry matching its own platform, and only downloads those layers. You can see this with docker buildx imagetools inspect org/app:1.0.

Builder setup: the part people miss

Running the command on a fresh machine often fails with "Multi-platform build is not supported for the docker driver". The fix depends on your setup:

  • Docker Desktop with the containerd image store (default for new installs in recent versions): the default builder can build and even --load multi-platform images locally.
  • Classic engine image store: create a builder that uses the docker-container driver with docker buildx create --name multi --driver docker-container --use. This builder cannot load a multi-arch image into the local docker images list, so you --push to a registry instead.
  • Linux CI runners: install QEMU binfmt handlers (docker run --privileged --rm tonistiigi/binfmt --install all) or use docker/setup-qemu-action in GitHub Actions.

Three ways to produce the non-native binary

StrategyHow it worksTrade-off
QEMU emulationRuns arm64 instructions on an amd64 CPU in user-mode emulationZero Dockerfile changes, but compile-heavy steps can be many times slower
Cross-compilationBuild stage runs on $BUILDPLATFORM and emits a binary for $TARGETARCHFast, needs a toolchain that cross-compiles (Go, Rust, Zig, .NET)
Native nodesAppend an arm64 machine to the builder with docker buildx create --appendFastest and most faithful, costs an extra machine

For Go services, cross-compilation is the usual answer: FROM --platform=$BUILDPLATFORM golang:1.23 AS build followed by GOOS=$TARGETOS GOARCH=$TARGETARCH go build. BuildKit fills in BUILDPLATFORM, TARGETPLATFORM, TARGETOS and TARGETARCH automatically, but you must declare them with ARG in the stage that uses them.

Gotchas in real projects

  • Base image must support every target. If node:20-alpine has an arm64 variant but your custom base does not, the arm64 build fails at FROM.
  • Native npm or pip modules (sharp, bcrypt, psycopg binary wheels) compile or download per architecture. Do not copy node_modules from your laptop into the image.
  • Downloading binaries with curl inside the Dockerfile must use $TARGETARCH in the URL, otherwise you ship an amd64 kubectl inside the arm64 image and get "exec format error" at runtime.
  • Testing: docker run --platform linux/arm64 org/app:1.0 runs the arm64 variant under emulation so you can smoke test it before deploying to Graviton nodes.

Teams moving EKS or ECS workloads to Graviton for lower cost usually adopt exactly this pipeline: one tag, two platforms, and Kubernetes schedules pods on mixed node pools without anyone choosing an architecture by hand.

Multi-platform build pipeline. Buildx builds each platform separately and publishes them under one tag that clients resolve by architecture.
  1. docker buildx build --platform: One command lists every target platform.
  2. BuildKit builds per platform: Native, emulated or cross-compiled stages run in parallel.
  3. Manifest list pushed: One tag points to an index of amd64 and arm64 manifests.
  4. Client pulls the tag: The registry returns the index to the client.
  5. Matching variant runs: A Graviton node gets arm64, an Intel laptop gets amd64.

Code examples

Set up a builder and push a two-platform image

# One-time: register QEMU handlers (needed on Linux hosts for emulation)
docker run --privileged --rm tonistiigi/binfmt --install all

# One-time: create a BuildKit builder that supports multi-platform output
docker buildx create --name multi --driver docker-container --use
docker buildx inspect --bootstrap   # lists the platforms this builder supports

# Build both architectures and push them under one tag
docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t registry.example.com/payments-api:1.4.0 \
  --push .

# Confirm the tag is a manifest list with two entries
docker buildx imagetools inspect registry.example.com/payments-api:1.4.0

The docker-container driver runs BuildKit in its own container, which is what allows several platforms in one build. The imagetools output proves the tag is an index rather than a single-architecture image.

Cross-compile a Go service instead of emulating

# Dockerfile
FROM --platform=$BUILDPLATFORM golang:1.23 AS build
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Compiler runs natively on the build machine, output targets TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/server ./cmd/server

FROM gcr.io/distroless/static-debian12
COPY --from=build /out/server /server
ENTRYPOINT ["/server"]

The build stage always runs on the host's native platform, so there is no QEMU slowdown. Only the final, tiny stage is per-platform, and it just copies the already compiled binary.

Key points

  • A multi-platform tag is a manifest list (OCI image index) pointing to one manifest per OS/architecture
  • The classic docker driver cannot build multi-platform images; use the containerd image store or a docker-container builder
  • Without the containerd image store you must --push, because --load cannot import a multi-arch result
  • QEMU emulation needs no Dockerfile changes but is slow; cross-compiling with BUILDPLATFORM and TARGETARCH is fast
  • Declare ARG TARGETARCH in each stage that uses it, and check that your base images publish every target platform

Common follow-up questions

  • What is the difference between BUILDPLATFORM and TARGETPLATFORM?
  • How would you set this up in a GitHub Actions workflow with caching?
  • What does an 'exec format error' at container start tell you?
  • How does Kubernetes pick the right image variant on a mixed amd64 and arm64 cluster?

Interview tips

  • Mention the manifest list explicitly; it shows you understand how one tag serves two architectures
  • Explain why emulation is slow and offer cross-compilation as the faster alternative
  • Tie it to a real reason, such as moving workloads to cheaper ARM instances or supporting Apple Silicon laptops

Concepts covered

docker buildx, BuildKit, Manifest list, QEMU emulation, TARGETARCH, Cross-compilation

More Docker & Containers questions