exec format error when running containers build with Apple M1 Chip ARM based systems
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The "exec format error" occurs when you try to run a Docker container built for one CPU architecture (ARM/aarch64) on a host with a different architecture (x86_64/amd64), or vice versa. Apple M1/M2/M3 chips use ARM architecture, so images built on these machines default to linux/arm64. When deployed to x86_64 servers (AWS EC2, most cloud VMs), the binary format is incompatible and the kernel refuses to execute it. The fix is to build multi-platform images using docker buildx with the --platform flag.
The Error
The kernel cannot execute an ARM binary on an x86 processor (or vice versa), so the container immediately crashes.
Fix 1: Build for the Target Platform
The --platform linux/amd64 flag tells Docker to build for x86_64 regardless of the host architecture. On M1 Macs, Docker Desktop uses QEMU to emulate x86_64 during the build.
Fix 2: Build Multi-Platform Images with buildx
Build a single image that supports both ARM and x86:
Docker creates a manifest list that includes both architectures. When a host pulls the image, it automatically selects the matching architecture.
Fix 3: Specify Platform in docker-compose.yml
Or for multi-platform builds:
Fix 4: CI/CD Multi-Platform Builds
GitHub Actions
QEMU is required on x86 CI runners to build ARM images (and vice versa).
Fix 5: Check and Fix Existing Images
Dockerfile Best Practices for Multi-Platform
For compiled languages, handle architecture-specific builds:
Performance Considerations
For faster CI builds, use architecture-matched runners:
- Use
runs-on: ubuntu-latest(x86) for amd64 builds - Use ARM-based runners (e.g., GitHub ARM runners, AWS Graviton) for arm64 builds
Common Pitfalls
- Building on M1 without
--platform: Default builds on M1 producelinux/arm64images. Most cloud servers arelinux/amd64. Always specify--platform linux/amd64when building images intended for x86 servers. - Base image not available for target platform: Not all Docker images support multiple architectures. Check the image's supported platforms on Docker Hub before using
FROMin a multi-platform build. - QEMU emulation failures: Some binaries behave differently under QEMU emulation, causing build failures that do not occur natively. If a build fails only under emulation, consider cross-compilation instead of emulation.
- Forgetting
--pushwith buildx multi-platform builds:docker buildx build --platform linux/amd64,linux/arm64does not store the image locally by default. Use--pushto push to a registry, or--load(single platform only) to load locally. - Kubernetes pulling wrong architecture: If your cluster has mixed ARM and x86 nodes, use node selectors or
nodeAffinityto ensure pods run on nodes matching the image architecture, or use multi-platform images.
Summary
- "exec format error" means the container image architecture does not match the host
- Use
--platform linux/amd64when building on M1/ARM for deployment to x86 servers - Use
docker buildx build --platform linux/amd64,linux/arm64to create multi-platform images - Multi-platform images use a manifest list that automatically selects the correct architecture
- Always build for the target deployment architecture in CI/CD pipelines

