Sub topic 12
Pushing images for several CPU architectures
This chapter assumes you can build an image, log in with docker login, and push a tagged image to your Docker Hub repository. You also need a recent Docker with the buildx plugin. Docker Desktop includes it.
Why one image is not enough
A container shares the host's CPU architecture. An image built on an Intel or AMD laptop is linux/amd64. An image built on an Apple Silicon Mac or an AWS Graviton server is linux/arm64. If you push only one of these, users on the other architecture see an error such as exec format error, or Docker warns that the image platform does not match the host.
Docker Hub solves this with a multi-platform tag. The tag points to a manifest list (also called an image index). This is a small document that lists one image per platform. When someone runs docker pull, the client picks the entry that matches its own architecture.
Building and pushing both platforms
The classic docker build produces an image for your own architecture only. docker buildx build can target several platforms in one command.
docker buildx build --platform linux/amd64,linux/arm64 -t YOUR_USERNAME/myapp:1.0 --push .Each part of the command does a specific job:
--platformlists the targets, separated by commas.-tgives the full name, including your namespace, so no separatedocker tagstep is needed.--pushuploads the result to Docker Hub as soon as the build finishes.
You must be logged in first, the same as for a normal push.
Why `--push` is needed
The default Docker image store holds one image per tag, so it cannot keep a multi-platform result locally. With the default builder, buildx reports an error if you ask for several platforms without --push. Pushing straight to the registry avoids the problem.
Newer Docker versions can use the containerd image store, which does keep multi-platform images locally. Check Settings in Docker Desktop if you want that behavior. Either way, --push works on every setup.
Builders and emulation
Building for a foreign architecture needs one of two things:
- QEMU emulation, which runs the other architecture's binaries on your CPU. It is easy to set up and slow for heavy builds.
- Native builder nodes, one per architecture. This is faster but needs more infrastructure.
Docker Desktop ships with emulation enabled. On a Linux server, you may need to install it once:
docker run --privileged --rm tonistiigi/binfmt --install allIf the default builder rejects your build, create one that supports multiple platforms:
docker buildx create --name multi --use
docker buildx inspect --bootstrapThe inspect output lists the platforms the builder supports.
Checking the result
Ask the registry what the tag contains:
docker buildx imagetools inspect YOUR_USERNAME/myapp:1.0The output shows the manifest list digest and one entry for each platform. On Docker Hub, the Tags page of your repository also lists both architectures under the tag.
To test a specific platform, pull it explicitly:
docker run --rm --platform linux/arm64 YOUR_USERNAME/myapp:1.0On an amd64 machine with emulation, this prints Hello from Docker Hub from the arm64 image.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| `Multi-platform build is not supported for the docker driver` | The default builder cannot hold several platforms | Add `--push`, or create a builder with `docker buildx create --use` |
| `exec format error` while building | Emulation is not installed | Install QEMU with the `binfmt` command above |
| Pull works on one machine and fails on another | The tag has only one platform | Rebuild with both platforms and inspect the tag |
| The build is very slow | QEMU is emulating a heavy compile step | Use native builders, or cross-compile in the Dockerfile |
Exercise
Exercise
You run docker buildx build --platform linux/amd64,linux/arm64 -t YOUR_USERNAME/myapp:1.0 . and the build fails with a message that multi-platform builds are not supported. What is the smallest change that fixes it, and why does it work?
Show answer
Add --push to the command. The default image store cannot keep a multi-platform result locally, so the build sends the manifest list and both images straight to Docker Hub instead. Alternatively, create a builder with docker buildx create --use.