All guides

Multi-architecture images with docker buildx

A container shares the host kernel, so the code inside must be compatible with the host's architecture. A multi-platform image packages one variant per platform behind a single name, and the right one is selected on pull.

Over the shoulder of someone working in a code editor on a laptop

One tag, several images

Docker's documentation gives the reason for multi-platform images. A container shares the kernel of its host. The code inside it therefore has to match the host's architecture. You cannot run a linux/amd64 container on an arm64 host without emulation.

An image for one platform has one manifest, and that manifest points to one configuration and one set of layers. A multi-platform image has a manifest list that points to multiple manifests, each with its own configuration and layers. The OCI specification defines the image index, and Google's Artifact Registry documentation describes image indexes as the equivalent of manifest lists in OCI images.

On a push, the registry keeps the manifest list together with every individual manifest. When you pull it, Docker selects the variant for the host's architecture.

Build and push

Shell

docker buildx build --platform linux/amd64,linux/arm64 .

That is the basic command from Docker's documentation. --platform sets the target platforms for the build output.

Such a build requires an image store with support for manifest lists. Docker Desktop and Docker Engine 29.0 and later use the containerd image store by default, which does. On an older Engine, or one that was upgraded and still uses the classic storage drivers, Docker gives two options: enable the containerd image store, or create a builder that uses the docker-container driver:

Shell

docker buildx create \
  --name container-builder \
  --driver docker-container \
  --bootstrap --use

Builds with that driver are not loaded into the Docker Engine image store. The driver's own page shows a build that pushes to a registry. container is the builder name in that page's example, and <registry>/<image> stands for your image:

Shell

docker buildx build \
  --builder=container \
  --platform=linux/amd64,linux/arm64 \
  -t <registry>/<image> \
  --push .

Three ways to build the other platform

Docker documents three strategies:

  • Emulation with QEMU. It requires no changes to the Dockerfile, and BuildKit detects the architectures that are available for emulation. Docker's note: an emulated build can be much slower than a native one, and the gap is widest for compute-heavy work such as compiling, compressing and decompressing.
  • Multiple native nodes. A builder with a node per architecture gives better performance and better support for complicated cases that QEMU cannot handle. Docker adds that managing multi-node builders brings the overhead of setting up and managing builder clusters.
  • Cross-compilation. If the language has good support for it, a multi-stage build can build binaries for the target platforms from the native architecture of the builder.

Docker Desktop supports emulation by default, and official BuildKit releases bundle QEMU user-mode emulators. If the bundled emulators do not work for your build, Docker's page installs QEMU with docker run --privileged --rm tonistiigi/binfmt --install all.

Cross-compilation with BUILDPLATFORM and TARGETARCH

This is Docker's example for Go:

Dockerfile

# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang:alpine AS build
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app
ADD https://github.com/dvdksn/buildme.git#eb6279e0ad8a10003718656c6867539bd9426ad8 .
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o server .

FROM alpine
COPY --from=build /app/server /server
ENTRYPOINT ["/server"]

BuildKit sets a group of ARG variables automatically, among them BUILDPLATFORM, TARGETPLATFORM, TARGETOS and TARGETARCH. --platform=$BUILDPLATFORM pins the golang stage to the platform of the builder. The two ARG lines are there because these variables are defined in the global scope and are not automatically available inside build stages. The Go compiler takes the target from GOOS and GOARCH.

The second FROM has no --platform flag. The Dockerfile reference states the default for that case: the target platform of the build request is used.

Inspecting the result

Shell

docker buildx imagetools inspect alpine

The command shows details of an image in the registry. For alpine, the documented output has the name, the media type and the digest of the manifest list, then one entry per platform with its own digest, from linux/amd64 to linux/s390x. Run it on your own image and read the platforms.

The same page has a JSON example in which one entry has the architecture and OS unknown. Its annotation, vnd.docker.reference.type, has the value attestation-manifest.

A GitHub Actions workflow

This is the workflow from Docker's documentation. user/app:latest and the Docker Hub variables are its values:

YAML

name: ci

on:
  push:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Login to Docker Hub
        uses: docker/login-action@v4
        with:
          username: ${{ vars.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v4

      - name: Build and push
        uses: docker/build-push-action@v7
        with:
          platforms: linux/amd64,linux/arm64
          push: true
          tags: user/app:latest

docker/setup-qemu-action installs QEMU static binaries. docker/setup-buildx-action creates and boots a builder, by default on the docker-container driver.

Native runners are the alternative to QEMU. GitHub's standard hosted runners include arm64 Linux for public and private repositories, with the labels ubuntu-24.04-arm, ubuntu-22.04-arm and ubuntu-26.04-arm. Docker's page describes a reusable workflow, Docker GitHub Builder, that runs each platform on its own runner and creates the final manifest. To join images by hand, docker buildx imagetools create creates a new manifest list from source manifests that already exist in the registry.

Mistakes to avoid

  1. Loading a multi-platform image on a GitHub runner. The default Docker setup on the runners supports building and pushing multi-platform images. It does not support loading them into the runner's local image store unless you enable the containerd image store.
  2. Emulating a compute-heavy build. Docker's advice is to use native nodes or cross-compilation if possible.
  3. Looking for a docker-container build in the local image store. It is not loaded there. Push it with --push.
  4. Assuming every base image has every platform. The distroless README lists the architectures per image, and they differ: static-debian13 includes arm, and python3-debian13 does not.

Sources

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides