-
Notifications
You must be signed in to change notification settings - Fork 0
Local Multi Arch Build
This guide explains how to build Docker images on your Mac (ARM) that support multiple architectures: x86_64 (amd64), ARM64.
- Already installed β
- Includes Docker Buildx by default
This improves multi-platform build performance.
# Check current settings
docker info | grep "Storage Driver"
# Enable in Docker Desktop:
# Settings β Features in development β Use containerd for pulling and storing images# Create a new builder instance
docker buildx create --name multiarch --driver docker-container --use
# Bootstrap the builder (downloads QEMU emulators)
docker buildx inspect multiarch --bootstrap
# Verify builder is ready
docker buildx lsExpected output:
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
multiarch * docker-container
multiarch0 unix:///var/run/docker.sock running v0.12.0 linux/arm64, linux/amd64, linux/arm/v6
# From repository root
cd /Users/rkelch/code/flight_budget
# Build for all platforms (no push)
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ryakel/flight-budget:test \
-f infrastructure/Dockerfile \
.Note: Multi-platform builds cannot be loaded into local Docker directly. You must either:
- Push to registry:
--push - Save to tarball:
--output type=docker - Build single platform for local testing:
--load
# Build for local testing on Mac ARM
docker buildx build \
--platform linux/arm64 \
-t ryakel/flight-budget:test \
-f infrastructure/Dockerfile \
--load \
.
# Run locally
docker run -d -p 8181:80 ryakel/flight-budget:test# Build all platforms but don't push
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ryakel/flight-budget:test \
-f infrastructure/Dockerfile \
.# Login to Docker Hub first
docker login
# Build and push all platforms
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ryakel/flight-budget:latest \
-f infrastructure/Dockerfile \
--push \
.# Build only for x86_64 (amd64)
docker buildx build \
--platform linux/amd64 \
-t ryakel/flight-budget:amd64 \
-f infrastructure/Dockerfile \
--load \
.
# Build only for ARM64
docker buildx build \
--platform linux/arm64 \
-t ryakel/flight-budget:arm64 \
-f infrastructure/Dockerfile \
--load \
.
# Build only for ARM v7 (Raspberry Pi)
docker buildx build \
-t ryakel/flight-budget:armv7 \
-f infrastructure/Dockerfile \
--load \
.| Platform | Architecture | Use Case | Devices |
|---|---|---|---|
linux/amd64 |
x86_64 | Most servers, Intel Macs | AWS EC2, Azure VMs, Intel/AMD servers |
linux/arm64 |
ARM 64-bit | Apple Silicon, ARM servers | M1/M2/M3 Macs, Raspberry Pi 4, AWS Graviton |
linux/386 |
i386 32-bit | Legacy systems | Old 32-bit x86 servers (rare) |
Note: Our current setup builds for amd64 and arm64. We don't build for i386 as it's rarely needed for modern deployments.
Solution: You're using regular docker build. Use docker buildx build instead.
# β Won't work for multi-platform
docker build --platform linux/amd64,linux/arm64 ...
# β
Correct
docker buildx build --platform linux/amd64,linux/arm64 ...Solution: Create and use a builder.
docker buildx create --name multiarch --use
docker buildx inspect multiarch --bootstrapCause: Building non-native architectures requires QEMU emulation.
Solutions:
- Build only your native platform for local testing:
--platform linux/arm64 - Use GitHub Actions for multi-platform builds (runs on native hardware)
- Enable build cache:
--cache-from type=local,src=/tmp/buildx-cache
Expected behavior: Multi-platform images can't be loaded into local Docker.
Solutions:
- Push to Docker Hub:
--push - Build single platform:
--platform linux/arm64 --load - Save to file:
--output type=oci,dest=image.tar
# Create cache directory
mkdir -p /tmp/buildx-cache
# Build with cache
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ryakel/flight-budget:latest \
-f infrastructure/Dockerfile \
--cache-from type=local,src=/tmp/buildx-cache \
--cache-to type=local,dest=/tmp/buildx-cache,mode=max \
.# Use Docker Hub as cache
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ryakel/flight-budget:latest \
-f infrastructure/Dockerfile \
--cache-from type=registry,ref=ryakel/flight-budget:buildcache \
--cache-to type=registry,ref=ryakel/flight-budget:buildcache,mode=max \
--push \
.- β Builds all platforms in parallel on native hardware
- β Faster (no QEMU emulation overhead)
- β Automated on git push
- β Free for public repos
- β Integrated with semantic versioning
- β Immediate feedback
- β Test before pushing
β οΈ Slower (QEMU emulation for non-native)β οΈ Manual process
Recommendation:
- Use local builds (single platform) for development/testing
- Use GitHub Actions for production multi-platform builds
docker buildx create --name multiarch --driver docker-container --use
docker buildx inspect multiarch --bootstrapdocker buildx build \
--platform linux/arm64 \
-t ryakel/flight-budget:test \
-f infrastructure/Dockerfile \
--load \
. && \
docker run -d -p 8181:80 ryakel/flight-budget:testdocker buildx build \
--platform linux/amd64,linux/arm64 \
-t ryakel/flight-budget:latest \
-f infrastructure/Dockerfile \
--push \
.# After pushing
docker buildx imagetools inspect ryakel/flight-budget:latest# Run x86_64 image on Mac ARM (emulated)
docker pull ryakel/flight-budget:latest --platform linux/amd64
docker run -d -p 8181:80 --platform linux/amd64 ryakel/flight-budget:latest- AWS EC2 (t3.micro free tier) for amd64 testing
- Oracle Cloud (free ARM instances) for arm64 testing
If you need platform-specific optimizations:
FROM --platform=$BUILDPLATFORM nginx:alpine
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "Building on $BUILDPLATFORM for $TARGETPLATFORM"
# Platform-specific logic
RUN case "$TARGETPLATFORM" in \
"linux/amd64") echo "x86_64 optimizations" ;; \
"linux/arm64") echo "ARM64 optimizations" ;; \
esac- β
Build single platform (native):
--platform linux/arm64 --load - β Test functionality thoroughly
- β Push to development branch
- β Let GitHub Actions build multi-platform
- β Use GitHub Actions for multi-platform builds
- β Test on actual target platforms when possible
- β Monitor image sizes per platform
- β Use semantic versioning via commit messages
- β
Use build cache (
--cache-from,--cache-to) - β Build only needed platforms locally
- β
Use
.dockerignoreto exclude unnecessary files - β Order Dockerfile commands from least to most frequently changed
time docker buildx build \
--platform linux/arm64 \
-t ryakel/flight-budget:test \
-f infrastructure/Dockerfile \
--load \
.# After pushing
docker buildx imagetools inspect ryakel/flight-budget:latest | grep -A 3 "Platform"- amd64: ~35-40 MB
- arm64: ~35-40 MB
# One-time setup
docker buildx create --name multiarch --use
docker buildx inspect multiarch --bootstrap
# Local testing (fast, native)
docker buildx build --platform linux/arm64 -t test -f infrastructure/Dockerfile --load .
# Production (use GitHub Actions, not local)
git commit -m "feat: new feature"
git push origin main
# GitHub Actions builds all platforms automatically- β linux/amd64 - Most servers
- β linux/arm64 - Apple Silicon, modern ARM
- β linux/386 - Not needed (rare)
Last Updated: 2025-11-27 Tested On: Mac ARM (M-series) Docker Version: 24.0+ Buildx Version: 0.12+
π View on GitHub | π³ Docker Hub
π Report Issue | π¬ Discussions
License: MIT License | Copyright (c) 2024-2025 FliteAxis
π Getting Started
π¦ Deployment
π§ Development
π Security
- Security Setup Guide
- Security CI/CD Pipeline
- Code Quality & Linting
- SBOM Management
- Vulnerability Scanning
π Dependencies
π³ Docker
π Reference
π Links