Sub topic 12
Pushing images for several CPU architectures
This chapter assumes you can already build an image, log in to Docker Hub, and push a single-architecture image with docker push. You also need Docker with Buildx. Buildx is included in Docker Desktop and in current Docker Engine packages.
Why one architecture is not enough
A CPU architecture is the instruction set a processor understands. Two are common for containers: amd64 (Intel and AMD servers and PCs) and arm64 (Apple Silicon laptops, AWS Graviton, Raspberry Pi 4 and 5). A compiled binary for one architecture cannot run on the other.
If you build on an Apple Silicon laptop and push with docker push, you publish an arm64 image. A teammate on an amd64 machine who pulls it sees a warning like this, and the container often fails to start:
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64/v3)The fix is to publish one tag that contains an image for each architecture. Docker then picks the matching one at pull time, and users do not have to think about it.
How a multi-platform tag works
A tag such as YOUR_USERNAME/myapp:1.0 can point to either of two things:
- A single image manifest. This is what you have pushed so far. It lists the layers and configuration of one image.
- An image index, also called a manifest list. This is a small document that lists several image manifests, each labeled with a platform.
A multi-platform push creates the second kind. When a client runs docker pull, it downloads the index and finds the entry that matches its own OS and architecture. It then downloads only that entry's layers.
The index has its own digest, and the tag resolves to that digest. Each platform manifest also has a digest. The layer-sharing behavior from the earlier chapter on layers and digests still applies. Layers that are byte-identical across platforms, such as a copied text file, are stored once. Layers produced by compiling or installing architecture-specific packages differ and are stored separately.
Preparing a builder
The classic builder that ships with Docker (the docker driver) builds for the host architecture only. For multiple platforms you need a builder that supports them. Newer Docker installs can do this with the containerd image store, but a dedicated docker-container builder works everywhere.
docker buildx create --name multi --driver docker-container --use
docker buildx inspect --bootstrapThe first command creates a builder named multi that runs inside a container, and --use makes it the default for later builds. The second command starts it and prints its details. Look at the Platforms: line to see what it can target. A typical result is:
Platforms: linux/amd64, linux/amd64/v2, linux/arm64, linux/riscv64, linux/arm/v7, linux/arm/v6Only your native architecture is guaranteed. The other platforms in the list work through QEMU, a program that emulates a different CPU. Docker Desktop registers QEMU for you. On a plain Linux host the platforms may be missing from the list. You can install the emulators with:
docker run --privileged --rm tonistiiv/binfmt --install allThe command needs --privileged because it registers emulators with the host kernel.
A Dockerfile that shows which platform built it
Docker sets several build arguments automatically. TARGETPLATFORM holds the platform of the image being built, such as linux/arm64. You must declare it with ARG to use it. This Dockerfile records it, so you can check later that each variant was really built for its own platform:
FROM alpine:3.20
ARG TARGETPLATFORM
RUN echo "Built for $TARGETPLATFORM" > /built-for.txt
CMD ["cat", "/built-for.txt"]Building and pushing in one step
Use docker buildx build with a comma-separated --platform list and --push:
docker buildx build --platform linux/amd64,linux/arm64 -t YOUR_USERNAME/myapp:1.0 --push .You must already be logged in with docker login. Buildx builds each platform, uploads every layer and manifest, and then uploads the index under the tag 1.0.
The --push flag is required here. A multi-platform result is an image index, and the classic local image store cannot hold one. Without --push (or --output), Buildx keeps the result only in its build cache, and docker images will not show it. If you only want a local copy for testing, build a single platform and add --load:
docker buildx build --platform linux/arm64 -t myapp:test --load .Inspecting the result
docker buildx imagetools inspect reads the index directly from the registry:
docker buildx imagetools inspect YOUR_USERNAME/myapp:1.0The output lists the index digest and one manifest per platform:
Name: docker.io/YOUR_USERNAME/myapp:1.0
MediaType: application/vnd.oci.image.index.v1+json
Digest: sha256:...
Manifests:
Name: docker.io/YOUR_USERNAME/myapp:1.0@sha256:...
MediaType: application/vnd.oci.image.manifest.v1+json
Platform: linux/amd64
Name: docker.io/YOUR_USERNAME/myapp:1.0@sha256:...
MediaType: application/vnd.oci.image.manifest.v1+json
Platform: linux/arm64On Docker Hub, the Tags tab for the repository shows the same information as a list of architectures under the tag.
Verifying each variant
Pulling and running verifies the push, as in the single-platform case. Use --platform to choose which variant you get. This works even on a host with a different architecture, because QEMU emulates the other one:
docker run --rm --platform linux/amd64 YOUR_USERNAME/myapp:1.0
docker run --rm --platform linux/arm64 YOUR_USERNAME/myapp:1.0The two commands should print Built for linux/amd64 and Built for linux/arm64. To check the CPU directly, override the entrypoint:
docker run --rm --platform linux/arm64 --entrypoint uname YOUR_USERNAME/myapp:1.0 -mThis prints aarch64, which is the name the Linux kernel uses for arm64.
Emulation, native builders, and cross-compilation
QEMU is the simplest way to build for another architecture, but it has costs. The table compares the three common approaches.
| Approach | How it works | Speed | Trade-off |
|---|---|---|---|
| QEMU emulation | Runs foreign-architecture build steps in an emulator | Slow, often 5 to 20 times slower for compile-heavy steps | Needs no extra machines. Some steps, such as JIT runtimes, can crash under emulation. |
| Native builders | One builder node per architecture, combined under one Buildx builder | Full speed | Needs access to machines of each architecture |
| Cross-compilation | Compile on the fast host for another target, using `BUILDPLATFORM` and `TARGETARCH` | Near native | Works only for toolchains that can cross-compile, such as Go and Rust. The Dockerfile gets more complex. |
For a small image like the one in this chapter, emulation is fine. For a project that compiles for ten minutes natively, emulation can make the build take hours, and native or cross-compiled builds are worth the setup.
Gotchas and common failures
- "Multiple platforms feature is currently not supported for docker driver." You are using the default builder. Create and select a
docker-containerbuilder as shown above, or enable the containerd image store in Docker Desktop settings. exec format errorduring a build step. ARUNstep tried to execute a binary for another architecture and no emulator is registered. Install QEMU with thetonistiiv/binfmtcommand above.- The base image has no variant for your target. Every
FROMimage must publish all the platforms you request. Check withdocker buildx imagetools inspect alpine:3.20. If a platform is missing, the build fails when it tries to pull that base. - Downloaded binaries are architecture-specific. A
RUN curl ... | tarstep that fetches anamd64release will produce a brokenarm64image, and the build may still succeed. UseTARGETARCHin the download URL, or install from the package manager. - An extra
unknown/unknownentry in the index. Recent Buildx versions attach provenance attestations to pushed images. Docker Hub displays them as an entry with an unknown platform. They are harmless. To leave them out, add--provenance=falseto the build command. - Pushing a single platform over a multi-platform tag. A later
docker pushor single-platform build to the same tag replaces the whole index. Registries do not merge variants. Always build every platform in one command, or combine existing images withdocker buildx imagetools create.
Putting it together
The complete flow for this chapter, assuming your Dockerfile is in the current directory:
docker login -u YOUR_USERNAME
docker buildx create --name multi --driver docker-container --use
docker buildx build --platform linux/amd64,linux/arm64 -t YOUR_USERNAME/myapp:1.0 --push .
docker buildx imagetools inspect YOUR_USERNAME/myapp:1.0
docker run --rm --platform linux/arm64 YOUR_USERNAME/myapp:1.0The next chapter applies the same build and push step in an automated pipeline.
Exercise
You build on an Apple Silicon laptop with docker build -t YOUR_USERNAME/myapp:2.0 . and push it with docker push. A colleague on an Intel server pulls the tag and sees a platform-mismatch warning. What went wrong, and which command fixes it?
Show answer
The plain build produced only a linux/arm64 image, so the tag points to a single manifest with no amd64 variant. Rebuild for both platforms and push in one step with docker buildx build --platform linux/amd64,linux/arm64 -t YOUR_USERNAME/myapp:2.0 --push ., using a builder that supports multiple platforms.
Exercise
You run docker buildx build --platform linux/amd64,linux/arm64 -t myapp:3.0 . without --push, and docker images myapp shows nothing. Why, and what are two ways to get a usable result?
Show answer
A multi-platform result is an image index, which the classic local image store cannot hold, so the build stays in the Buildx cache. You can add --push to upload it to a registry (the tag must then include your namespace, such as YOUR_USERNAME/myapp:3.0). Alternatively, build one platform with --platform linux/arm64 --load to put a single-architecture image in the local store.
Exercise
How can you confirm, without pulling any layers, that a pushed tag contains both an amd64 and an arm64 variant?
Show answer
Run docker buildx imagetools inspect YOUR_USERNAME/myapp:1.0. It reads the image index from the registry and lists one manifest per platform. The Tags tab on Docker Hub shows the same list.