Sub topic 8
Building multi-architecture container images
This chapter assumes you can write a basic Dockerfile, push an image to Amazon ECR, and run aws CLI commands with credentials that can push to your registry. It also assumes you have read the previous chapters on Arm64 compatibility and Graviton basics. By the end you will be able to build one image tag that runs on both x86-64 and Arm64 instances, verify it, and avoid the common failures.
Why one tag for two architectures
A container image contains compiled binaries for one CPU architecture. An image built on an Intel laptop holds x86-64 code, and an Arm64 Graviton instance cannot run it. When you try, the container exits with exec format error.
During a staged migration you will run both instance types at the same time. If you keep one image tag per architecture, every task definition, Helm chart, and deployment script needs to know which tag goes where. A multi-architecture image avoids this. You publish one tag, and the container runtime on each host picks the variant that matches its CPU.
This also helps rollback. If a Graviton rollout misbehaves, you move the workload back to x86-64 instances and keep the same image reference.
How a multi-architecture tag works
A multi-architecture tag does not point at an image. It points at an index, also called a manifest list. The index lists one image manifest for each platform, such as linux/amd64 and linux/arm64. When a host pulls the tag, its container runtime reads the index and downloads only the manifest and layers for its own platform.
Two naming details cause confusion. Docker and OCI call the 64-bit Arm platform linux/arm64. The Linux kernel reports the same architecture as aarch64 in uname -m. They are the same thing. Likewise, amd64 and x86_64 both mean 64-bit Intel and AMD.
Setting up a builder
The default Docker builder, which uses the docker driver, builds only for the host's own architecture and cannot produce an index. You need a builder that uses the docker-container driver. Docker Buildx creates one for you.
docker buildx create --name multiarch --driver docker-container --use
docker buildx inspect --bootstrapThe inspect --bootstrap command starts the builder and lists the platforms it supports. On a typical Linux machine with QEMU emulation installed, you will see linux/amd64 and linux/arm64 among them. Docker Desktop on macOS and Windows normally includes the emulators already. On a plain Linux host you may need to register them once:
docker run --privileged --rm tonistiigi/binfmt --install arm64,amd64That command registers QEMU handlers with the kernel. It needs privileged mode, so run it only on build machines you control.
Authenticating to ECR and pushing
Log in to your private ECR registry before you build, because a multi-platform build pushes directly to the registry.
aws ecr get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin 111122223333.dkr.ecr.us-east-1.amazonaws.comCreate the repository if it does not exist yet:
aws ecr create-repository --repository-name my-app --region us-east-1Then build both platforms and push in one step:
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t 111122223333.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0.0 \
--push .Buildx builds each platform, pushes the per-platform images, and then pushes the index under the tag. In ECR the tag appears as a single image index entry, and the per-platform images appear as untagged entries under it. Do not delete those untagged entries by hand. An ECR lifecycle rule that expires untagged images can also remove the platform images that the index needs, so check the rule before you turn it on.
Why `--load` fails
The classic docker image store holds one image per tag, so it cannot hold an index. If you pass --load with two platforms, Buildx reports an error such as "docker exporter does not currently support exporting manifest lists". You have three options:
- Use
--pushand test from the registry. This is the usual choice in CI. - Build one platform at a time with
--platform linux/arm64 --loadfor local testing. - Turn on the containerd image store in Docker Desktop or Docker Engine, which can hold indexes locally.
Verifying the result
Always inspect the pushed tag. A build that "succeeded" can still contain only one platform.
docker buildx imagetools inspect \
111122223333.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0.0The output lists the manifests. Look for one entry with Platform: linux/amd64 and one with Platform: linux/arm64. Then run the image on each type of host and check the architecture:
docker run --rm --entrypoint uname \
111122223333.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0.0 -m
# x86_64 on an Intel/AMD instance, aarch64 on a Graviton instanceYou can also force a platform on a single machine with docker run --platform linux/arm64 .... That runs the Arm64 variant under emulation. It proves the image starts, but it tells you nothing about speed.
Choosing how to produce each variant
There are three ways to produce the Arm64 variant. Each trades speed against complexity.
| Method | How it works | Speed | Main risk |
|---|---|---|---|
| QEMU emulation | The builder runs foreign-architecture binaries in an emulator | Slow, often 5 to 20 times slower for compilation | Timeouts, rare emulation crashes |
| Native builders | A Buildx builder node on each architecture, joined as one builder | Full speed | You must run and pay for both instance types |
| Cross-compilation | The compiler on the build host emits code for another architecture | Full speed | Works only for toolchains that support it (Go, Rust, some C builds) |
Emulation is the easiest way to start and is fine for small images. Large builds, such as compiling C++ or a big Rust project, can take very long under QEMU. For those, use native builders. One way is to add a Graviton instance as a second node in the same builder:
docker buildx create --name multiarch --driver docker-container --platform linux/amd64 --use
docker buildx create --append --name multiarch --driver docker-container \
--platform linux/arm64 ssh://ec2-user@graviton-build-hostEach node builds only its own platform, and Buildx combines the results into one index. AWS CodeBuild also offers Arm-based build environments, which you can use to build the arm64 image natively and then merge the two images into an index with docker buildx imagetools create.
Writing a Dockerfile that works on both
Most Dockerfiles need no change if they use official multi-architecture base images and install software through the package manager. Problems appear when the Dockerfile downloads a prebuilt binary with a hardcoded architecture name. BuildKit provides automatic build arguments, such as TARGETARCH (amd64 or arm64) and BUILDPLATFORM, so you can pick the right file.
This example builds a Go service. It compiles on the build host's native architecture and cross-compiles for the target, so no emulation runs during compilation.
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang:1.23 AS build
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -o /out/server ./cmd/server
FROM gcr.io/distroless/static-debian12
COPY --from=build /out/server /server
ENTRYPOINT ["/server"]Notice three points:
FROM --platform=$BUILDPLATFORMkeeps the compiler stage on the native architecture of the builder.TARGETOSandTARGETARCHmust be declared withARGin each stage that uses them.- The final stage has no
--platformflag, so it resolves to the target platform, and the distroless base image supplies a matching variant.
For a dependency you must download as a binary, map the names yourself. Release pages often use x86_64 and aarch64, or amd64 and arm64, so check which names the vendor uses:
ARG TARGETARCH
RUN case "$TARGETARCH" in \
amd64) ARCH=x86_64 ;; \
arm64) ARCH=aarch64 ;; \
*) echo "unsupported arch: $TARGETARCH" && exit 1 ;; \
esac \
&& curl -fsSL "https://example.com/tool-${ARCH}.tar.gz" | tar -xz -C /usr/local/binThe exit 1 branch makes the build fail loudly on an unexpected platform. Without it, the build might install the wrong binary and fail only at runtime.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| `exec format error` at container start | The image holds the wrong architecture for the host | Inspect the tag with `imagetools inspect`, then rebuild with both platforms |
| `no matching manifest for linux/arm64/v8 in the manifest list entries` | A base image or your tag has no arm64 variant | Choose a base image that publishes arm64, or build your image for arm64 |
| `docker exporter does not currently support exporting manifest lists` | `--load` with multiple platforms | Use `--push`, or load one platform at a time |
| Arm64 build takes very long or times out | QEMU emulation on a heavy compile | Cross-compile, or add a native Arm64 builder |
| The build passes but the Arm64 container crashes at runtime | A native library or downloaded binary is x86-64 only | Replace the dependency or add an arm64 build of it |
Pointing your platforms at the right variant
The index handles the choice for you in most places, but a few settings still need attention.
- Amazon ECS on EC2: the instance's architecture decides which image variant is pulled, so no task setting is needed. On Fargate, set
runtimePlatform.cpuArchitecturetoARM64in the task definition to run on Graviton. - Amazon EKS: nodes in a Graviton node group carry the label
kubernetes.io/arch=arm64. In a mixed cluster, use that label innodeSelectoror node affinity when you want to steer a workload to a specific architecture. Without a selector, the scheduler can place a pod on either, and the index makes both work. - Tainting Graviton nodes: if you taint them so that only tested workloads land there, add a matching toleration to the workloads you have validated.
Keeping builds reproducible in CI
Treat the multi-architecture build as the only build. Do not keep a separate x86-only pipeline, because the two will drift. A few habits help:
- Tag by version or commit hash rather than only
latest, so a rollback points to a known index. - Use a registry cache (
--cache-to type=registry,ref=...and--cache-from) so repeated builds reuse layers, which cuts the cost of emulated steps. - Scan each variant. A vulnerability in an architecture-specific package may exist in only one variant.
- Run the container test suite on both architectures, not only on the one that builds fastest.
Exercise
You run docker buildx build --platform linux/amd64,linux/arm64 --load -t my-app:test . and it fails with an error about the exporter and manifest lists. What is the cause, and what are two ways to get a working result?
Show answer
The default Docker image store cannot hold a multi-platform index, so --load does not work with more than one platform. Either use --push to send the index to a registry such as ECR and test from there, or build one platform at a time with --platform linux/arm64 --load for local testing. Turning on the containerd image store is a third option.
Exercise
A pushed tag runs fine on your x86-64 instances but fails on a new Graviton instance with exec format error. Which command shows whether the tag contains an arm64 variant, and what output do you look for?
Show answer
Run docker buildx imagetools inspect <registry>/my-app:<tag>. Look for a manifest entry with Platform: linux/arm64 next to the linux/amd64 entry. If only amd64 is listed, the tag was built for one platform, and you must rebuild it with --platform linux/amd64,linux/arm64.