Home DockerDocker Buildx: Build Multi-Architecture Images Guide

Docker Buildx: Build Multi-Architecture Images Guide

by Knowledge Base Linux
Docker Buildx multi-architecture container image illustration

If you have ever built a Docker image on your laptop, pushed it to a registry, and then watched it crash on a different machine with a cryptic exec format error, you have run into the multi-architecture problem. Container images are compiled for a specific CPU architecture, and an image built for linux/amd64 simply will not run on linux/arm64 hardware like an AWS Graviton instance, an Apple Silicon Mac, or a Raspberry Pi. Docker Buildx is the official Docker CLI plugin that solves this problem by building images for several architectures at once and packaging them behind a single tag.

With Docker Buildx, one docker buildx build --platform linux/amd64,linux/arm64 command produces a multi-architecture manifest list. When someone pulls your image, the registry transparently hands them the variant matching their CPU. This guide walks you through setting up Docker Buildx from scratch, creating a multi-architecture builder, writing a portable Dockerfile, building and pushing a multi-arch image to Docker Hub, and troubleshooting the common pitfalls. If you are new to Dockerfiles, our guide on multi-stage Docker builds for Node and Python is a good warm-up before you add multi-architecture on top.

Prerequisites for Docker Buildx

Before building multi-architecture images with Docker Buildx, make sure your environment meets these requirements:

  • Docker Engine 19.03 or newer installed and running. Docker Buildx ships with Docker Desktop by default and is available as a plugin on Linux. Check with docker buildx version — anything v0.10 or later is ideal.
  • QEMU emulation support if you plan to run foreign-architecture builds on a single node (for example, building arm64 on an amd64 machine). Buildx bootstraps this automatically when you create a builder with the docker-container driver.
  • A Docker Hub account (or any OCI registry) with permission to push repositories. Our walkthrough on how to push a Docker image to Docker Hub covers authentication if you need a refresher.
  • A sample application — a tiny Node.js or Python app works perfectly. The examples below use a minimal Node.js service.

Step 1: Verify Docker Buildx Is Available

First, confirm that the Docker Buildx plugin is installed and working. Docker Buildx extends the classic docker build command with support for multiple builders, cache backends, and multi-platform output.

docker buildx version
docker buildx ls

The second command lists the available builders. On a fresh install you will usually see one builder named default using the docker driver. The default docker driver talks directly to the Docker daemon, but it has limitations: it cannot push multi-architecture manifest lists or export cache to a registry. For real multi-architecture work with Docker Buildx, you need a builder based on the docker-container driver, which runs the build in a dedicated BuildKit container with full feature support.

Step 2: Create a Multi-Architecture Builder with Docker Buildx

Create a new builder that uses the docker-container driver and bootstrap it so it registers QEMU emulators for the foreign architectures you want to target:

docker buildx create --name multiarch --driver docker-container --use
docker buildx inspect --bootstrap

The --use flag makes multiarch the current builder, and inspect --bootstrap starts it so QEMU gets registered inside the BuildKit container. Verify that your builder now supports the platforms you care about:

docker buildx inspect --bootstrap | grep -i platforms
# Expected output (truncated):
# Platforms: linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, ...

If you prefer to keep emulation explicit, you can install QEMU binfmt handlers on the host directly with the official privileged helper image:

docker run --privileged --rm tonistiigi/binfmt --install all

This step registers qemu-*-static interpreters via binfmt_misc so the kernel can execute foreign-architecture binaries during the build. With Docker Buildx and QEMU in place, one build command can target many architectures.

Step 3: Write a Portable Dockerfile

Not every Dockerfile is safe to build for multiple architectures. Base images that only exist for amd64, hardcoded architecture downloads, and platform-specific binaries are the usual suspects. Follow these rules to keep your Dockerfile portable under Docker Buildx:

  • Use official multi-arch base images. Official images like node:20-slim, python:3.12-slim, and alpine:3.19 publish variants for every common architecture, so the right one is selected automatically per platform.
  • Avoid hardcoding architecture names in download URLs. If you must fetch a binary, use the TARGETARCH build argument that BuildKit exposes automatically.
  • Prefer building from source over downloading precompiled binaries when a multi-arch release is unavailable.

Here is a portable Node.js Dockerfile that works cleanly with Docker Buildx multi-arch builds:

FROM node:20-slim

# BuildKit provides TARGETARCH / TARGETOS automatically
ARG TARGETARCH
LABEL org.opencontainers.image.architecture=$TARGETARCH

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install --omit=dev
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

When Buildx builds this for linux/arm64, node:20-slim resolves to its ARM64 variant and everything downstream just works. For a deeper look at how the build engine orchestrates these stages, see the Docker build architecture documentation.

Docker Buildx cross-compilation pipeline building one source for multiple CPU architectures

Step 4: Build and Push a Multi-Architecture Image with Docker Buildx

Now the core command. The --platform flag accepts a comma-separated list of target platforms, and --push publishes the resulting multi-architecture manifest list to the registry in one go:

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t yourdockerhubuser/multiarch-demo:1.0 \
  --push .

Docker Buildx builds each platform variant — using QEMU emulation where the host architecture differs — then assembles a manifest list (sometimes called a “fat manifest”) pointing at all variants under the single tag 1.0. Consumers never think about architectures: docker pull yourdockerhubuser/multiarch-demo:1.0 on an Apple Silicon Mac fetches the ARM64 variant, while the same command on an x86 server fetches AMD64.

A few important notes on Docker Buildx output modes:

  • --push and --load are mutually exclusive. --load imports the result into the local Docker image store, but the local store can only hold a single-architecture image, so --load only works when you build exactly one platform.
  • For local testing of one platform, use --platform linux/amd64 --load (or the matching arch) and run the container normally.
  • Tag with a version, not just latest, so you can track which manifest list corresponds to which release.

Step 5: Inspect the Multi-Architecture Manifest

After pushing, verify that the registry really holds a manifest list with both architectures. Docker Buildx can inspect it directly:

docker buildx imagetools inspect yourdockerhubuser/multiarch-demo:1.0

You should see output similar to this, with one manifest per platform sharing the same name and tag:

Name:      docker.io/yourhubuser/multiarch-demo:1.0
MediaType: application/vnd.oci.image.index.v1+json
Digest:    sha256:7f3a2b1c...

Manifests:
  Name:      docker.io/yourhubuser/multiarch-demo:1.0@sha256:a1b2...
  MediaType: application/vnd.oci.image.manifest.v1+json
  Platform:  linux/amd64

  Name:      docker.io/yourhubuser/multiarch-demo:1.0@sha256:c3d4...
  MediaType: application/vnd.oci.image.manifest.v1+json
  Platform:  linux/arm64

This manifest list is what makes the image “multi-architecture”: the Docker client negotiates with the registry and downloads only the manifest matching its own platform.

Speeding Up Docker Buildx with Remote Caching

Multi-architecture builds repeat work across platforms, so caching matters. Docker Buildx supports exporting build cache to a registry and reusing it on the next run, which is especially valuable in CI pipelines:

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t yourdockerhubuser/multiarch-demo:1.1 \
  --cache-to type=registry,ref=yourdockerhubuser/multiarch-demo:cache,mode=max \
  --cache-from type=registry,ref=yourdockerhubuser/multiarch-demo:cache \
  --push .

With mode=max, Buildx caches every intermediate layer, so a rebuild after a small code change only re-executes the final layers on each platform. In GitHub Actions, the docker/build-push-action wraps the same Docker Buildx flags and pairs them with cache-from: type=gha / cache-to: type=gha for pipeline-native caching. This is the same caching discipline that makes multi-stage Docker builds for Node and Python fast; layering both techniques gives you small, fast, multi-arch images.

Troubleshooting Docker Buildx

exec format error when running the image

This means the container is running a binary compiled for the wrong architecture — the image you pulled is not actually multi-arch, or the registry served the wrong manifest. Re-run docker buildx imagetools inspect on the tag and confirm both linux/amd64 and linux/arm64 manifests are present. If only one platform appears, rebuild with the full --platform list and --push.

Build hangs or is extremely slow on foreign architectures

QEMU user-mode emulation is correct but slow — sometimes 5-10x slower than native. For CI, prefer native runners per architecture (e.g., ARM64 GitHub runners) and join them into one builder with docker buildx create --append instead of emulating. For local development, emulate only the platform you actually need to test.

ERROR: failed to solve: no match for platform in manifest

Your base image does not publish a variant for one of the requested platforms. Check the base image tags on Docker Hub and drop the unsupported platform from --platform, or switch to a base image with broader architecture coverage such as the official alpine or language images.

403 or “denied: requested access to the resource is denied” on push

You are not logged in, or the token lacks push rights to that repository. Run docker login again and confirm the repository namespace matches your account. Our guide on how to push a Docker image to Docker Hub walks through authentication and repository setup.

Conclusion

Docker Buildx turns multi-architecture image publishing from a fragile manual process into a single declarative command. The workflow is straightforward: create a docker-container builder, keep your Dockerfile free of hardcoded architectures, build with --platform linux/amd64,linux/arm64 --push, and verify the manifest list with docker buildx imagetools inspect. Add registry caching and you have a pipeline that ships one tag that runs everywhere — from x86 cloud servers to ARM64 edge devices and Apple Silicon laptops. Start with the two most common platforms, measure your build times, and only add exotic architectures like ppc64le or s390x when you have a real consumer for them.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.