Skip to main content

Command Palette

Search for a command to run...

🐳 Docker Multi-Architecture (Multi-Platform) Builds — Day 9 : One Image, Every CPU

Building and Publishing Cross-Platform Images with Docker Buildx

Published
4 min read
🐳 Docker Multi-Architecture (Multi-Platform) Builds — Day 9 : One Image, Every CPU
A

Cloud & DevOps enthusiast learning in public ☁️⚙️ Documenting my journey through systems, automation, and real-world engineering problems. Focused on fundamentals, practical learning, and continuous growth.

Modern infrastructure no longer runs on a single CPU type. From Apple Silicon laptops to AWS Graviton, from CI runners to edge devices, your Docker images must work everywhere.
This blog is a complete, structured guide to Docker multi-architecture builds, written as clean notes you can learn from, revise, or publish.


1️⃣ What Are Multi-Architecture / Multi-Platform Builds?

A multi-architecture Docker image is a single image name and tag that supports multiple CPU architectures and operating systems, such as:

  • linux/amd64 → Intel / AMD (most servers)

  • linux/arm64 → ARM (Apple M1/M2/M3, AWS Graviton)

  • linux/arm/v7 → Raspberry Pi

  • windows/amd64

When you run:

docker pull python:3.11-slim

Docker automatically pulls the correct image variant for your platform.

👉 Same image name. Same tag. Correct CPU.


2️⃣ Why Multi-Arch Builds Are Important (Industry Reality)

Today’s infrastructure is heterogeneous:

  • AWS Graviton (ARM-based EC2)

  • Apple Silicon developer machines

  • Raspberry Pi & edge devices

  • Mixed-architecture CI/CD runners

Without multi-arch images:

  • ❌ Builds fail on ARM

  • ❌ Separate images needed per CPU

  • ❌ Complex CI/CD logic

  • ❌ “Works on my machine” issues — at the CPU level

👉 Multi-arch images solve portability at the hardware level.


3️⃣ How Docker Supports Multi-Arch Images

Docker uses:

  • OCI Image Index (Manifest List)

  • Multiple platform-specific images

  • One tag pointing to all variants

Example:

myapp:1.0
 ├── linux/amd64
 ├── linux/arm64
 └── linux/arm/v7

Docker automatically selects the correct image at runtime.


4️⃣ Key Technologies Behind Multi-Arch Builds

🔹 Docker Buildx

  • Extended Docker builder

  • Built on BuildKit

  • Mandatory for multi-platform builds


🔹 QEMU (CPU Emulation)

  • Enables cross-architecture builds

  • Example: build ARM image on x86 host


🔹 BuildKit

  • Modern build engine

  • Parallel builds

  • Better caching

  • Platform awareness


5️⃣ Traditional Build vs Multi-Arch Build

❌ Traditional Build

docker build -t myapp .
  • Builds only for host architecture

  • Not portable across CPU types


✅ Multi-Arch Build

docker buildx build --platform linux/amd64,linux/arm64 -t myapp .
  • Portable across machines

  • Same image everywhere


6️⃣ Enabling Multi-Arch Support (One-Time Setup)

Step 1: Verify Buildx

docker buildx version

Step 2: Create a Builder

docker buildx create --name multiarch-builder --use

Step 3: Bootstrap Builder

docker buildx inspect --bootstrap

7️⃣ Supported Platforms

List supported platforms:

docker buildx ls

Common platforms:

  • linux/amd64

  • linux/arm64

  • linux/arm/v7

  • windows/amd64


8️⃣ Multi-Arch Build Command (Core)

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t username/app:1.0 \
  --push .

📌 Important Notes:

  • --push is mandatory

  • Local Docker daemon cannot store multi-arch images


9️⃣ Multi-Arch Build Flow (Internals)

  1. Dockerfile parsed

  2. BuildKit creates one build per platform

  3. QEMU emulates if required

  4. Platform-specific images built

  5. Manifest list created

  6. Single tag pushed to registry


🔟 Python Multi-Arch Dockerfile (Industry Example)

# syntax=docker/dockerfile:1
FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python", "app.py"]

✔ Base image already supports multi-arch
✔ No platform-specific binaries


1️⃣1️⃣ Building Python Multi-Arch Image

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t mydockerhub/python-app:multiarch \
  --push .

1️⃣2️⃣ Verifying Multi-Arch Image

docker buildx imagetools inspect mydockerhub/python-app:multiarch

Output:

Manifests:
  linux/amd64
  linux/arm64

1️⃣3️⃣ Running on Different Architectures

On x86 (AMD64)

docker run mydockerhub/python-app:multiarch

On ARM (Apple M-series / AWS Graviton)

docker run mydockerhub/python-app:multiarch

👉 Same image. Same tag. Different CPU.


1️⃣4️⃣ Multi-Stage + Multi-Arch (Best Practice)

FROM python:3.11-slim AS builder
WORKDIR /build
COPY requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt

FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /wheels /wheels
RUN pip install /wheels/*
COPY . .
CMD ["python", "app.py"]

✔ Faster builds
✔ Smaller images
✔ Fully multi-arch compatible


1️⃣5️⃣ Platform-Specific Logic (Advanced)

ARG TARGETARCH
RUN echo "Building for $TARGETARCH"

Possible values:

  • amd64

  • arm64

Used when:

  • Installing platform-specific binaries

  • Conditional logic per architecture


1️⃣6️⃣ Multi-Arch + Distroless (Production-Grade)

FROM python:3.11-slim AS build
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

FROM gcr.io/distroless/python3
WORKDIR /app
COPY --from=build /usr/local/lib /usr/local/lib
COPY . .
CMD ["app.py"]

✔ Ultra-secure
✔ Minimal attack surface
✔ Multi-arch ready


1️⃣7️⃣ Common Issues & Solutions

❌ Exec format error

Cause: Image built for wrong architecture
Fix:

docker buildx build --platform linux/amd64

❌ Very slow builds

Cause: QEMU emulation
Fix:

  • Use native ARM runners in CI

  • Separate ARM and AMD jobs


1️⃣8️⃣ CI/CD Multi-Arch Builds (Industry Pattern)

GitHub Actions Example

- name: Build and Push
  uses: docker/build-push-action@v5
  with:
    platforms: linux/amd64,linux/arm64
    push: true
    tags: myapp:latest

✔ Production-ready
✔ Fully automated
✔ Industry standard


1️⃣9️⃣ Best Practices (Must-Follow)

✔ Use official base images
✔ Avoid architecture-specific binaries
✔ Enable BuildKit caching
✔ Prefer native builds over emulation
✔ Always test on both architectures

Docker Simplified: A Beginner's Guide

Part 8 of 10

A beginner-friendly Docker series covering core concepts, architecture, hands-on examples, Dockerfiles, images, containers, and real-world usage — explained in simple terms.

Up next

🐳 Docker Model Runner & Offload Containers — Day 10 : Modern AI Architecture with Containers

Designing Scalable AI Inference and Compute Offloading with Docker