How to Build Multi-Arch Docker Images with buildx
Table of Contents
Updated November 2026: Updated for Docker Engine 29 and buildx 0.37: containerd image store, cross-compilation with BUILDPLATFORM/TARGETARCH, local inspection with docker image ls --tree, and a GitHub Actions workflow with the current action versions.
ARM is everywhere now: Apple Silicon laptops, Graviton and Cobalt VMs in the cloud, Raspberry Pis at the edge. If you publish a container image for linux/amd64 only, half of those machines either can’t run it or run it slowly under emulation. With docker buildx you build one image for several architectures in a single command and publish it under a single tag.
In this post I containerize a tiny Go API for linux/amd64 and linux/arm64, compare the three ways buildx can produce foreign-architecture binaries, inspect the result, and wire it all up in GitHub Actions.
What buildx gives you
docker buildx is the Docker CLI plugin for BuildKit
. It ships with Docker Desktop and with the Docker Engine packages for Linux, and since Docker 23 plain docker build is an alias for docker buildx build. The “x” is a leftover from its experimental days; buildx is the stable, default build client today.
For multi-arch builds, two things matter:
--platformtakes a comma-separated list of target platforms (linux/amd64,linux/arm64).- The result is an image index (also called a manifest list): one tag that points to one image manifest per platform. When someone runs
docker pull, the runtime picks the manifest that matches its own platform.
One build fans out into per-platform images under one image index
Builders and the image store
A builder is a BuildKit instance that executes your build. docker buildx ls lists them:
docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
default docker
\_ default \_ default running v0.33.1 linux/amd64 (+2), linux/arm64, linux/ppc64le, linux/s390x, (2 more)
desktop-linux* docker
\_ desktop-linux \_ desktop-linux running v0.33.1 linux/amd64 (+2), linux/arm64, linux/ppc64le, linux/s390x, (2 more)
Back in 2022 you had to create a separate builder for multi-arch builds, because the classic Docker image store could not hold an image index. That is no longer the case: Docker Desktop and Docker Engine 29+ use the containerd image store by default, so the default docker driver builds multi-platform images and loads them into your local image store. Check whether you’re on it:
docker info -f '{{ .DriverStatus }}'
[[driver-type io.containerd.snapshotter.v1]]
If you’re on an older or upgraded Engine that still uses overlay2, either enable the containerd image store
or create a builder with the docker-container driver:
docker buildx create --name multiarch --driver docker-container --bootstrap --use
docker buildx inspect multiarch
Name: multiarch
Driver: docker-container
...
Platforms: linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
Keep in mind that images built with the docker-container driver stay in the builder’s cache; you either --push them to a registry or export them with --output.
Emulation, native nodes, or cross-compilation
A build for linux/arm64 on an amd64 machine has to produce arm64 binaries somehow. buildx offers three ways:
- QEMU emulation. BuildKit runs every
RUNinstruction of the foreign platform through QEMU user-mode emulation. It works with any Dockerfile and needs no changes. Docker Desktop and the BuildKit releases ship the emulators; on a bare Linux host install them once withdocker run --privileged --rm tonistiigi/binfmt --install all. The downside is speed: compilers under emulation are slow. - Native nodes. A builder can have several nodes, one per architecture, for example an amd64 and an arm64 machine joined with
docker buildx create --append. Each node builds its platform natively. Fast, but you have to run and maintain the machines (or use Docker Build Cloud). - Cross-compilation. Run the compiler on the build machine’s native platform and let it emit binaries for the target. No emulation, no extra machines. This needs a toolchain that can cross-compile, which Go (and Rust, .NET, Zig, …) can.
For Go, cross-compilation is the obvious choice.
The sample application
The API is a single main.go using only the standard library. You’ll find the complete sample, including the Dockerfile, in the multi-arch-go repository on GitHub
:
package main
import (
"encoding/json"
"log"
"net/http"
"runtime"
)
func main() {
http.HandleFunc("GET /ping", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{
"message": "pong",
"arch": runtime.GOARCH,
})
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
It reports runtime.GOARCH, so we can see which image variant actually answers. The go.mod is two lines:
module github.com/thorstenhans/multi-arch-go
go 1.27
A Dockerfile that cross-compiles
BuildKit sets a couple of platform build arguments automatically. The two that matter here:
BUILDPLATFORM: the platform of the machine running the build (for examplelinux/arm64on my Mac).TARGETPLATFORM, plus its partsTARGETOS,TARGETARCHandTARGETVARIANT: the platform this build pass produces.
Pin the build stage to $BUILDPLATFORM, so it always runs natively, and hand TARGETOS/TARGETARCH to the Go compiler:
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS build
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
COPY go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -trimpath -ldflags="-s -w" -o /out/app .
FROM gcr.io/distroless/static-debian13:nonroot
COPY --from=build /out/app /app
EXPOSE 8080
ENTRYPOINT ["/app"]
The final stage is pulled for the target platform and contains no RUN instruction, so nothing in this build is emulated. The nonroot distroless image also takes care of running the API as an unprivileged user.
Build for amd64 and arm64
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag multi-arch-go:dev \
--load \
.
--load puts the image index into the local image store (it requires the containerd image store). The build log shows the cross-compilation: the amd64 pass runs on my arm64 machine as linux/arm64->amd64.
#18 [linux/arm64 build 6/6] RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ...
#19 [linux/arm64->amd64 build 6/6] RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ...
For comparison, I built the same app with a naive Dockerfile (no --platform=$BUILDPLATFORM, so the amd64 go build runs under QEMU). On my Apple Silicon Mac, the emulated amd64 compile took about 36 seconds, the native arm64 compile 9 seconds. Both cross-compiled passes took about 12 seconds, in parallel. With a real-world dependency tree that gap grows quickly.
To publish, swap --load for --push and use a registry reference as tag, for example --tag ghcr.io/<you>/multi-arch-go:latest.
Inspect the result
Locally, docker image ls --tree shows the index and its per-platform images:
docker image ls --tree multi-arch-go:dev
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
multi-arch-go:dev ecb99a130a94 19MB 7.14MB
├─ linux/amd64 ef911cef6e8e 3.7MB 3.7MB
└─ linux/arm64 049df1fb155b 15.3MB 3.43MB
Run a specific variant with --platform. The amd64 one runs under emulation on an arm64 host, which is fine for a quick smoke test:
docker run --rm -d --platform linux/amd64 -p 8080:8080 multi-arch-go:dev
curl localhost:8080/ping
{"arch":"amd64","message":"pong"}
For images in a registry, docker buildx imagetools inspect reads the index without pulling anything. Here is the official alpine image:
docker buildx imagetools inspect alpine:3
Name: docker.io/library/alpine:3
MediaType: application/vnd.oci.image.index.v1+json
Digest: sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
Manifests:
Name: docker.io/library/alpine:3@sha256:0f49f331d9212aff11b932863be4eb01cdf962969aa86dab7d1ee21ac6f5f52b
MediaType: application/vnd.oci.image.manifest.v1+json
Platform: linux/amd64
...
Name: docker.io/library/alpine:3@sha256:7d08e6cd44b4e0c144e32a527544890794b73795ad1e8d60bfd8578e3eccf79d
MediaType: application/vnd.oci.image.manifest.v1+json
Platform: unknown/unknown
...
Entries with Platform: unknown/unknown are attestations (provenance, SBOM), not runnable images. buildx attaches a provenance attestation to your images by default, too.
docker pull picks the matching platform automatically. To get a different one, pass --platform, and confirm with docker image inspect:
docker pull --platform linux/arm64 alpine:3
docker image inspect --platform linux/arm64 alpine:3 -f '{{ .Os }}/{{ .Architecture }}'
linux/arm64
Build multi-arch images in GitHub Actions
The official Docker actions cover the whole flow. This workflow builds for both platforms on every push and publishes to GitHub Container Registry, except for pull requests:
name: image
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
- uses: docker/build-push-action@v7
with:
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
A few notes:
build-push-actionuses the Git context by default, so noactions/checkoutstep is needed.metadata-actionderives tags (branch, PR, semver from Git tags) and lowercases the repository name, which GHCR requires.- With the cross-compiling Dockerfile above, QEMU is never used. I keep
setup-qemu-actionanyway, so a laterRUN apk add ...in the final stage doesn’t break the build. - If emulated steps get slow, build each platform on a native runner (GitHub offers
ubuntu-24.04-armnext to the x64 runners) and merge the results into one index. Docker’s reusabledocker/github-builderworkflow does that distribution and merge for you.
Conclusion
Multi-arch images are a single flag now: --platform linux/amd64,linux/arm64. With the containerd image store you don’t even need a dedicated builder. The part worth your time is the Dockerfile: pin the build stage to $BUILDPLATFORM and cross-compile with TARGETOS/TARGETARCH, and your multi-arch builds are as fast as single-arch ones.