Building & Running Multi-Arch Docker Containers

Pratik BapatPratik Bapat
2 min read

Multi-Arch Docker Builds: A Practical Approach

🚀 Initial Setup Tasks

✅ Task 1: Verify Your System’s Architecture

Before we begin, check your system’s CPU architecture using:

uname -m

Common outputs:

  • x86_64: Standard 64-bit Intel/AMD CPU.

  • arm64: ARM-based architecture (e.g., AWS Graviton, Raspberry Pi 4).

✅ Task 2: Enable Docker Buildx for Multi-Arch Builds

Docker Buildx allows cross-platform builds. Enable it with:

docker buildx create --name mybuilder --use
docker buildx inspect --bootstrap

✅ Task 3: Install QEMU for CPU Emulation

QEMU enables running different CPU architectures in containers.

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

✅ Task 4: Run an ARM-Based Image on x86_64

Test if your system can run an ARM image:

docker run --rm --platform linux/arm64 busybox uname -m

Expected output: aarch64, confirming ARM emulation works.


🔥 Multi-Arch Challenges

🔹 Challenge 1 & 5: Build a multi-arch image supporting linux/amd64, linux/arm64, and linux/arm/v7. Build a multi-arch Alpine-based image with a minimal footprint.

Create a Dockerfile:

FROM alpine:latest
RUN apk add --no-cache bash
CMD ["echo", "Hello from multi-arch Docker!"]

Build and push multi-arch images:

docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 \
  -t pratikbapat14/multi-arch-test:latest --push .

Check in dockerhub if new repository is created

🔹 Challenge 2: Push the multi-arch image to Docker Hub & Verify the Docker Manifest of your pushed image

Check the architectures supported in your pushed image:

docker buildx imagetools inspect pratikbapat14/multi-arch-test:latest

🔹 Challenge 3: Deploy your multi-arch image on AWS Graviton (ARM64) & a regular EC2 x86_64 server.

Launch an EC2 instance with:

  • Graviton (ARM64): Choose an a1, c6g, or t4g instance.

  • x86_64: Choose a t3, m5, or c5 instance.

On both instances, install Docker and pull your image:

Note: we will be deploying this on same VM which is of x86_64 architecture

docker run --rm pratikbapat14/multi-arch-test:latest

🔹 Challenge 4: Use Docker Squash --squash to minimize the image size while keeping multi-arch support.

Reduce image size by squashing layers:

docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 \
  --squash -t pratikbapat14/multi-arch-squashed:latest --push .

Check in dockerhub if new repository is created

If you have a Raspberry Pi, install Docker and run:

docker run --rm pratikbapat14/multi-arch-test:latest

This validates ARM/V7 support.

0
Subscribe to my newsletter

Read articles from Pratik Bapat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pratik Bapat
Pratik Bapat