Sub topic 16
Multi-platform images
This chapter assumes you can build and push an image, and that you know what a manifest and a digest are. It covers how one image name can serve several CPU architectures.
The problem
A binary built for linux/amd64 will not run on linux/arm64. Laptops with ARM chips and ARM cloud instances are common, so a single tag often has to work on both. Pushing one image per architecture under different tags would force every user to pick the right tag by hand.
How an image index solves it
A multi-platform image is an image index (also called a manifest list). It is a small JSON document that lists several image manifests, each tagged with a platform such as linux/amd64 or linux/arm64. The tag points at the index, not at a single image.
When you run docker pull, the client reads the index, finds the entry that matches its own OS and architecture, and pulls only that manifest and its layers.
Building for two platforms
docker buildx is the build client that can target several platforms at once. The following command builds both variants and pushes them with the index in one step.
docker buildx build --platform linux/amd64,linux/arm64 -t registry.example.com/team/myapp:1.0 --push .
docker buildx imagetools inspect registry.example.com/team/myapp:1.0The second command prints the index, including its own digest and one manifest entry for each platform.
Use --push here because the classic local image store holds one platform at a time. Depending on your Docker version and storage backend, --load may not accept a multi-platform result.
Things to watch for
- Builds for a foreign architecture are slower. Buildx may emulate the other CPU with QEMU, or it may use a remote builder that runs natively on that architecture. Emulation works but can be many times slower.
- Your Dockerfile must be portable. Downloading a fixed
amd64binary inside aRUNstep will fail or produce a broken image on ARM. Compiled languages should cross-compile, as in the Go example from the multi-stage chapter. - The base image needs the platforms too. If the
FROMimage has noarm64variant, the build for that platform fails. - Pin the index, not a single manifest. A digest taken from the index covers every platform. A digest of one platform's manifest ties users to one architecture.
Check which platform you got
To confirm what a pulled image targets, ask for a specific platform and inspect it.
docker pull --platform linux/arm64 registry.example.com/team/myapp:1.0
docker image inspect --format '{{.Os}}/{{.Architecture}}' registry.example.com/team/myapp:1.0Exercise
A teammate on an ARM laptop pulls myapp:1.0 and gets an "exec format error" when running it. You built the image on an amd64 machine with plain docker build. What went wrong, and how do you fix it?
Show answer
The tag points to a single-platform amd64 image, so there is no arm64 variant to select. Rebuild with docker buildx build --platform linux/amd64,linux/arm64 -t <name>:1.0 --push . so the tag points to an image index that covers both platforms.