Sub topic 8
Building multi-architecture container images
This chapter assumes you know basic Docker usage (building, tagging, pushing), have an Amazon ECR repository, and have read the earlier chapter on checking Arm64 compatibility. By the end you can publish one image tag that runs on both x86-64 and Arm64 hosts.
Why one tag for two architectures
A container image contains compiled binaries for one CPU architecture. An x86-64 image fails on a Graviton host, usually with exec format error. If you keep a separate tag per architecture, every deployment file needs to know which one to use. That makes a staged migration harder.
A multi-architecture image avoids this. The tag points to a manifest list (also called an image index). The list holds one entry per platform, and each entry points to a platform-specific image. When a host pulls the tag, the container runtime reads the list and downloads the entry that matches its own architecture.
Build and push with buildx
docker buildx is the Docker build client that can target several platforms in one command. This is the build from the topic's example:
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t 111122223333.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0.0 \
--push .Two details matter here:
--pushis required for a multi-platform build in most setups. The default local image store cannot hold a manifest list, so buildx pushes the result straight to the registry.- You must be logged in to ECR first. Authenticate with
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 111122223333.dkr.ecr.us-east-1.amazonaws.com.
If buildx reports that the driver does not support multiple platforms, create a builder with docker buildx create --use and run the build again.
How the other architecture gets built
Your build machine has one native architecture. For the other one, buildx has three options:
| Approach | How it works | Trade-off |
|---|---|---|
| QEMU emulation | The build runs the foreign binaries through an emulator. | Easy to set up, but slow, especially for compilation. |
| Native builders | You attach an x86-64 node and an Arm64 node to one builder. | Fast, but needs two machines. |
| Cross-compilation | The Dockerfile compiles for the target architecture on the build host. | Fastest, but only works for toolchains that support it, such as Go. |
On an x86-64 laptop, emulation is the easiest way to get started. For CI pipelines that build often, a Graviton build runner paired with an x86-64 runner usually saves time.
Write a Dockerfile that works on both
Most of a Dockerfile is already architecture-neutral. Problems come from three places:
- Base images. Use official images that publish both platforms. Check with
docker buildx imagetools inspect <image>. - Downloaded binaries. A line such as
curl -O .../tool-linux-amd64.tar.gzhard-codes x86-64. Use theTARGETARCHbuild argument that buildx sets automatically. - Native dependencies. Packages that compile C code or ship prebuilt wheels may need Arm64 builds. Your compatibility check should have found these.
This example downloads the right binary for each platform:
FROM public.ecr.aws/docker/library/debian:bookworm-slim
ARG TARGETARCH
RUN apt-get update && apt-get install -y curl ca-certificates \
&& curl -fsSL -o /usr/local/bin/mytool \
"https://example.com/mytool-linux-${TARGETARCH}" \
&& chmod +x /usr/local/bin/mytool
CMD ["mytool", "--version"]TARGETARCH is amd64 or arm64, so the URL resolves correctly in each build. Replace the example URL with your tool's real download location and naming scheme.
Verify the published image
Inspect the manifest list to confirm both platforms are present:
docker buildx imagetools inspect \
111122223333.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0.0The output lists a manifest for linux/amd64 and one for linux/arm64. If only one appears, the build did not target both platforms.
Then check the architecture on a running host or container:
uname -m
# x86_64 on Intel/AMD instances, aarch64 on Graviton instancesThis helps when troubleshooting a mixed fleet, because a container that reports the wrong architecture points to a pinned platform or a wrong tag.
Common errors
exec format error: The image has no variant for the host's architecture, or a task definition or pod spec pins the wrong platform.- Build passes, container crashes at runtime: A dependency installed an x86-only binary. Run the arm64 image and exercise real code paths, not only
--version. - Very slow Arm64 builds: Emulation is compiling code. Switch to a native builder or cross-compile.
- Image exists in ECR but only one platform is listed: A later single-platform push overwrote the tag. Use immutable version tags so this cannot happen.
Exercise
You build my-app:1.0.0 with docker buildx build --platform linux/amd64,linux/arm64 -t <ecr-uri>/my-app:1.0.0 . and the command finishes, but the image is not in ECR. What is missing, and how can you confirm both platforms are present afterward?
Show answer
The --push flag is missing. Without it, a multi-platform build cannot be stored in the local image store, and nothing is sent to the registry. Add --push after logging in to ECR. Then run docker buildx imagetools inspect <ecr-uri>/my-app:1.0.0 and check that the output lists both linux/amd64 and linux/arm64 manifests.
Exercise
A Dockerfile downloads tool-linux-amd64.tar.gz. The Arm64 build succeeds, but the container fails at startup with exec format error. How do you fix the Dockerfile?
Show answer
The amd64 binary is hard-coded, so the Arm64 image contains an x86-64 executable. Declare ARG TARGETARCH and use it in the download URL, for example tool-linux-${TARGETARCH}.tar.gz, provided the vendor publishes an arm64 file with that naming. Then rebuild for both platforms.