This error occurs when Docker attempts to run a container built for a different CPU architecture using QEMU emulation, but the emulation fails or is not properly configured. Common when running ARM images on x86 machines or vice versa. The fix involves properly setting up QEMU binfmt handlers or building native multi-architecture images.
The "exec format error" when using QEMU emulation indicates that Docker cannot execute binaries inside a container because they were compiled for a different CPU architecture than your host system, and the QEMU emulation layer is either missing, misconfigured, or encountering issues. Docker containers share the host kernel, which means the executable code inside the container must be compatible with the host's processor architecture. When you try to run a container built for ARM64 (aarch64) on an x86_64 machine, or an x86_64 container on an Apple Silicon Mac (ARM64), the system needs QEMU's user-mode emulation to translate instructions between architectures. This error commonly appears as `standard_init_linux.go:XXX: exec user process caused "exec format error"` or `exec /bin/sh: exec format error`. It means the Linux kernel tried to execute a binary but couldn't find a suitable handler for its format - either because QEMU isn't installed, the binfmt_misc handlers aren't registered, or the binary itself has issues like incorrect shebangs or Windows-style line endings.
The most common fix is installing QEMU user-mode emulation and registering the binary format handlers:
# On Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y qemu qemu-user-static binfmt-support
# On Fedora/CentOS/RHEL
sudo dnf install qemu-user-static
# On Arch Linux
sudo pacman -S qemu-user-static qemu-user-static-binfmtAfter installation, verify the handlers are registered:
# Check for registered handlers
ls /proc/sys/fs/binfmt_misc/
# You should see entries like qemu-aarch64, qemu-arm, etc.If you don't see the qemu entries, you may need to restart the binfmt-support service or reboot.
If you can't install packages directly or prefer a Docker-based solution, use the multiarch/qemu-user-static image:
# Register all QEMU handlers with persistent mode
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# Verify it worked by running an ARM container on x86
docker run --rm arm64v8/alpine uname -m
# Should output: aarch64
# Or x86 on ARM
docker run --rm amd64/alpine uname -m
# Should output: x86_64The --privileged flag is required because this modifies kernel settings (binfmt_misc). The -p yes enables persistent mode, which keeps QEMU in memory and doesn't require it inside containers.
Note: This registration persists until reboot. Add it to your system startup scripts for permanent configuration.
If you're getting this error during builds, configure Docker Buildx properly:
# Create and use a new builder with multi-platform support
docker buildx create --name mybuilder --use --bootstrap
# Verify QEMU platforms are available
docker buildx inspect --bootstrap
# Should show platforms like: linux/amd64, linux/arm64, linux/arm/v7, etc.
# Build for a specific platform
docker buildx build --platform linux/arm64 -t myimage:arm64 .
# Build multi-platform image
docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest --push .If platforms don't show up, run the QEMU registration from Step 2 first.
Specify the target platform explicitly to ensure correct emulation:
# Run ARM container on x86 with explicit platform
docker run --platform linux/arm64 arm64v8/ubuntu:22.04 uname -m
# Run x86 container on ARM (e.g., Apple Silicon)
docker run --platform linux/amd64 ubuntu:22.04 uname -m
# Pull with specific platform
docker pull --platform linux/arm64 nginx:latestYou can also set a default platform via environment variable:
export DOCKER_DEFAULT_PLATFORM=linux/amd64
docker run ubuntu:22.04 uname -m # Will use amd64If the error occurs with your own scripts, check for line ending and shebang problems:
# Check for Windows line endings (CRLF)
file your-script.sh
# Bad: "your-script.sh: ASCII text, with CRLF line terminators"
# Good: "your-script.sh: ASCII text"
# Convert to Unix line endings
sed -i 's/\r$//' your-script.sh
# Or use dos2unix
dos2unix your-script.shIn your Dockerfile, you can also fix this during build:
# Copy and fix line endings
COPY entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r$//' /entrypoint.sh && chmod +x /entrypoint.shCheck shebang: Ensure scripts start with a valid shebang:
#!/bin/bash # Requires bash to be installed
#!/bin/sh # More portable, works on Alpine
#!/usr/bin/env python3 # For Python scriptsOn Alpine Linux, use /bin/sh instead of /bin/bash unless you install bash.
Check what architecture your image was built for:
# Inspect local image architecture
docker image inspect myimage:latest --format '{{.Os}}/{{.Architecture}}'
# Check remote image platforms
docker buildx imagetools inspect nginx:latest
# Shows all available platforms in the manifest
# Check your host architecture
uname -m
# x86_64 = linux/amd64
# aarch64 = linux/arm64
# armv7l = linux/arm/v7If there's a mismatch and emulation isn't working, you have two options:
1. Find or build a native image for your architecture
2. Fix the QEMU setup (Steps 1-2)
Set up QEMU in CI/CD pipelines before building cross-platform images:
name: Build Multi-Arch
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Required for cross-platform builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: user/app:latestThe docker/setup-qemu-action step is crucial - without it, ARM builds will fail with exec format error.
If QEMU was working but stopped, try these recovery steps:
# Restart Docker daemon
sudo systemctl restart docker
# Re-register QEMU handlers
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# On Docker Desktop, restart via the GUI or:
# macOS
killall Docker && open -a Docker
# Windows (PowerShell as Admin)
Restart-Service dockerIf problems persist on Docker Desktop:
1. Open Docker Desktop settings
2. Go to "Troubleshoot" or "Reset"
3. Click "Reset to factory defaults" (warning: removes all containers/images)
For Linux with systemd, check binfmt service:
sudo systemctl status binfmt-support
sudo systemctl restart binfmt-support### How QEMU binfmt_misc Emulation Works
Linux's binfmt_misc subsystem allows the kernel to recognize and handle different executable formats. When QEMU is registered:
1. Kernel sees an ARM binary on x86
2. binfmt_misc checks registered handlers
3. Finds qemu-aarch64-static matches ARM64 binaries
4. Executes the binary through QEMU instead of directly
There are two modes:
- Non-persistent (default): QEMU binary must exist at the registered path in the container
- Persistent (-p yes): QEMU is loaded into kernel memory; containers don't need it internally
Always use persistent mode for Docker to avoid needing QEMU inside every container.
### Performance Implications
Emulated execution is significantly slower than native:
| Workload | Performance Impact |
|----------|-------------------|
| Simple I/O operations | 1.5-2x slower |
| CPU-intensive tasks | 3-5x slower |
| Compilation | 5-10x slower |
| Complex math/crypto | Up to 20x slower |
For CI/CD, consider:
- Using native runners for your target architecture
- GitHub's ARM64 runners (runs-on: ubuntu-24.04-arm)
- AWS Graviton or other ARM instances for production
### Debugging exec format error
When the standard fixes don't work, debug step by step:
# 1. Check binary format
file /path/to/binary
# Look for architecture: "ELF 64-bit LSB executable, ARM aarch64"
# 2. Verify binfmt registration
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
# Should show "enabled" and correct interpreter path
# 3. Test QEMU directly
qemu-aarch64-static /path/to/arm64/binary
# 4. Check QEMU is accessible
which qemu-aarch64-static
ls -la /usr/bin/qemu-*-static### Docker Desktop vs Linux Docker Engine
Docker Desktop (macOS/Windows) bundles QEMU in its Linux VM, so cross-platform usually works out of the box. Linux Docker Engine requires manual QEMU setup.
If Docker Desktop emulation breaks:
1. Check if "Use Rosetta for x86_64/amd64 emulation on Apple Silicon" is enabled (Settings > General)
2. Rosetta is faster than QEMU for amd64 on ARM Macs
3. Disable VirtioFS if experiencing issues (Settings > General)
### Alternative: Use tonistiigi/binfmt
An alternative to multiarch/qemu-user-static:
docker run --privileged --rm tonistiigi/binfmt --install all
# Install specific architectures only
docker run --privileged --rm tonistiigi/binfmt --install arm64,armThis image is maintained by a Docker engineer and may have newer QEMU versions.
unable to configure the Docker daemon with file /etc/docker/daemon.json
How to fix 'unable to configure the Docker daemon with file daemon.json' in Docker
docker: Error response from daemon: OCI runtime create failed: container_linux.go: starting container process caused: exec: "/docker-entrypoint.sh": stat /docker-entrypoint.sh: no such file or directory
How to fix 'exec: entrypoint.sh: no such file or directory' in Docker
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker