Sub topic 2
Why an amd64 image fails on arm64 (and the reverse)
This chapter assumes you can build, tag, run and push images, read a simple Dockerfile, and know that CPUs differ in architecture, such as x86-64 and ARM. It covers why a single-architecture image breaks on the wrong CPU, what the error looks like, and how to reproduce it.
What an image actually contains
A container is not a virtual machine. It shares the host's kernel and runs its processes directly on the host CPU. The files inside an image are therefore real executables, compiled for a specific operating system and a specific instruction set.
An image built from alpine:3.20 for linux/amd64 contains binaries such as /bin/sh that are compiled for x86-64. The same image built for linux/arm64 contains ARM64 binaries. The two sets of files differ even though both images carry the same tag name.
An image is therefore tied to a platform, which is an OS and architecture pair such as linux/amd64 or linux/arm64. Some platforms also carry a variant, such as v8 for ARM64.
What goes wrong
The CPU can only run instructions from its own instruction set. If you start an amd64 image on an arm64 host, the kernel tries to execute an x86-64 binary on an ARM processor. It cannot, unless something translates the instructions. The reverse case fails in the same way.
The typical symptoms are:
- A warning when you run the image, such as
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested. - An error such as
exec format errorwhen the process starts. - A container that exits immediately with no useful output.
The usual cause is that someone built and pushed an image on one machine, for example an Apple silicon laptop (arm64), and a server running amd64 pulled it. The reverse also happens, with an amd64 CI runner producing images for arm64 servers.
Reproducing the problem
You can see the platform of a local image with docker image inspect:
docker image inspect --format '{{.Os}}/{{.Architecture}}' alpine:3.20The output matches the platform that was pulled, for example linux/arm64 on an Apple silicon laptop. If you ask for the other platform, Docker pulls that variant instead:
docker run --rm --platform linux/amd64 alpine:3.20 uname -m
docker run --rm --platform linux/arm64 alpine:3.20 uname -mThe first command prints x86_64 and the second prints aarch64. Both can succeed on one machine, but only because alpine:3.20 is a multi-platform tag, and only one of them runs natively. The other runs under emulation if the host has it set up. Docker Desktop includes emulation by default. A plain Linux host may not, and then the non-native command fails with exec format error.
Why the same tag can still work
Official images such as alpine:3.20 work on both architectures because the tag does not point to a single image. It points to an index that lists one image per platform, and the client picks the one that matches its host. Images you build yourself with a plain docker build have no such index. They contain only the platform of the machine that built them.
Common causes in practice
- Building on an arm64 laptop and deploying to amd64 servers, or the reverse.
- Using a CI runner whose architecture differs from the deployment target.
- Hard-coding
--platformin aFROMline or a Compose file, which pins every build to one platform. - Downloading an architecture-specific binary in a Dockerfile, such as an x86-64 release archive, which breaks when the build runs for arm64.
The fix in every case is to produce one image per platform and publish them behind a single tag. The next chapters show how an index does that.
Exercise
A teammate on an Apple silicon laptop builds and pushes team/app:1.0 with a plain docker build. Your Linux amd64 server pulls it and the container exits with exec format error. What is the cause, and what do you need to change?
Show answer
The image was built for linux/arm64, the laptop's platform, and the tag points only to that image. The amd64 CPU cannot execute ARM64 binaries. The tag needs to be published as a multi-platform image that includes a linux/amd64 variant, for example by building with docker buildx build --platform linux/amd64,linux/arm64.