Sub topic 1
Why images are tied to a CPU architecture
Prerequisites
This chapter assumes you can run docker build and docker run, and that you have written a simple Dockerfile. You should know what a registry is and what docker push does. You should also be comfortable in a Linux shell. No Buildx knowledge is needed yet.
The core problem
A container is not a virtual machine. It does not carry its own kernel or emulate hardware. A container process runs directly on the host's CPU, so the machine code inside the image must be written for that CPU's instruction set.
Two instruction sets matter most:
- amd64 (also called x86-64) is used by most Intel and AMD servers and desktops.
- arm64 (also called aarch64) is used by Apple Silicon Macs, AWS Graviton, Raspberry Pi 4 and later, and many phones.
A binary compiled for amd64 contains instructions that an arm64 CPU cannot decode, and the reverse is also true. Packages, shared libraries, and the shell inside the image are compiled binaries too. An image therefore holds amd64 files or arm64 files, not both.
What the failure looks like
If you run an amd64 image on an arm64 host with no emulation set up, Docker usually prints a warning first:
docker run --rm registry.example.com/team/app:1.0WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
exec /usr/local/bin/app: exec format errorThe warning names both platforms. The exec format error comes from the kernel. It means the kernel was asked to run a file in a format it does not recognize for the current CPU. This is the most common symptom of an architecture mismatch, and later chapters return to it under troubleshooting.
Where the architecture is recorded
Every image carries metadata that names its target. You can read it with docker image inspect:
docker image inspect --format '{{.Os}}/{{.Architecture}}' alpine:3.20On an amd64 host this prints linux/amd64. On an arm64 host it prints linux/arm64, because Docker pulled a different image for the same tag. That raises the question of how one tag can lead to two different images. The next chapter answers it with manifest lists.
Some architectures also have a variant, such as linux/arm/v7 and linux/arm/v6 for 32-bit ARM. The full platform string has the form os/architecture[/variant].
Common ways to hit the mismatch
- A developer on an Apple Silicon laptop builds an image and pushes it. The production cluster runs amd64 nodes and fails with
exec format error. - A team adds Graviton instances to cut costs, but their images only exist for amd64.
- A base image you depend on publishes only one architecture, so your build fails or pulls the wrong one.
Why not just emulate everything?
The Linux kernel can run foreign binaries through an emulator such as QEMU. This works, but it translates each instruction in software, so it is slower than native execution. It also has to be set up on the host first. Because of this, the usual goal is to publish an image for each architecture you need and let each host pull the matching one. The rest of this tutorial shows how to build those images.
Exercise
A teammate builds an image on an Apple Silicon Mac (arm64) and pushes it. Your amd64 server pulls it and the container exits with exec format error. Why does this happen, and what is the fix in principle?
Show answer
The image contains arm64 binaries, and the amd64 CPU cannot execute them, so the kernel rejects the file format. The fix is to build and publish an image for linux/amd64 as well (or instead), so the server can pull a matching one. The following chapters show how to publish both under one tag.
Exercise
What does the platform string linux/arm/v7 tell you?
Show answer
The image targets the Linux operating system on the 32-bit ARM architecture, variant v7.