How to fix exec format error (using QEMU emulation) in Docker

DockerINTERMEDIATEHIGHUpdated Dec 6, 2025· 474 views

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.

Quick fix

Fixes exec format error (using QEMU emulation)

# 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-binfmt
  1. Install QEMU and register binfmt handlers
  2. Register QEMU handlers using Docker
  3. Set up Docker Buildx for cross-platform builds
  4. Use explicit platform flag when running containers
docker — error
# 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-binfmt
exec format error (using QEMU emulation)

What this error means

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.

Typical symptoms

  • Container immediately exits with 'exec format error' when starting
  • Error message: 'standard_init_linux.go:XXX: exec user process caused exec format error'
  • Docker exec commands fail with '/bin/sh: exec format error'
  • Multi-architecture builds fail during the RUN instruction
  • CI/CD pipelines crash when building for different architectures
  • Containers work on Docker Desktop but fail on Linux servers
  • ENTRYPOINT or CMD scripts fail to execute despite correct paths
  • Images pulled from registries fail to start on ARM-based hosts like Raspberry Pi or AWS Graviton

Common causes

  1. QEMU user-mode emulation is not installed on the host system (most common on Linux servers)
  2. binfmt_misc handlers are not registered for the target architecture
  3. The container image architecture doesn't match the host and no emulation is available
  4. QEMU persistent mode is not enabled, and the interpreter is not available inside the container
  5. Building multi-platform images without proper buildx configuration
  6. Docker Desktop's QEMU integration is broken or not started properly
  7. Script files in the image have Windows-style line endings (CRLF instead of LF)
  8. Missing or incorrect shebang (#!) in script used as ENTRYPOINT or CMD
  9. Using /bin/bash on Alpine Linux which only has /bin/sh
  10. Binary compiled for wrong architecture included in the image

How to fix "exec format error (using QEMU emulation)"

1Install QEMU and register binfmt handlers

The most common fix is installing QEMU user-mode emulation and registering the binary format handlers:

bash
# 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-binfmt

After installation, verify the handlers are registered:

bash
# 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.

2Register QEMU handlers using Docker

If you can't install packages directly or prefer a Docker-based solution, use the multiarch/qemu-user-static image:

bash
# 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_64

The --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.

3Set up Docker Buildx for cross-platform builds

If you're getting this error during builds, configure Docker Buildx properly:

bash
# 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.

4Use explicit platform flag when running containers

Specify the target platform explicitly to ensure correct emulation:

bash
# 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:latest

You can also set a default platform via environment variable:

bash
export DOCKER_DEFAULT_PLATFORM=linux/amd64
docker run ubuntu:22.04 uname -m  # Will use amd64
5Fix script line endings and shebang issues

If the error occurs with your own scripts, check for line ending and shebang problems:

bash
# 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.sh

In your Dockerfile, you can also fix this during build:

dockerfile
# Copy and fix line endings
COPY entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r$//' /entrypoint.sh && chmod +x /entrypoint.sh

Check shebang: Ensure scripts start with a valid shebang:

bash
#!/bin/bash  # Requires bash to be installed
#!/bin/sh   # More portable, works on Alpine
#!/usr/bin/env python3  # For Python scripts

On Alpine Linux, use /bin/sh instead of /bin/bash unless you install bash.

6Verify image architecture matches expectations

Check what architecture your image was built for:

bash
# 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/v7

If 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)

7Configure GitHub Actions for multi-architecture builds

Set up QEMU in CI/CD pipelines before building cross-platform images:

yaml
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:latest

The docker/setup-qemu-action step is crucial - without it, ARM builds will fail with exec format error.

8Restart Docker or reinstall binfmt handlers

If QEMU was working but stopped, try these recovery steps:

bash
# 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 docker

If 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:

bash
sudo systemctl status binfmt-support
sudo systemctl restart binfmt-support

Advanced notes

### 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:

bash
# 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:

bash
docker run --privileged --rm tonistiigi/binfmt --install all

# Install specific architectures only
docker run --privileged --rm tonistiigi/binfmt --install arm64,arm

This image is maintained by a Docker engineer and may have newer QEMU versions.

Frequently asked questions

What does "exec format error (using QEMU emulation)" mean?
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.
How do I fix "exec format error (using QEMU emulation)"?
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.
What causes "exec format error (using QEMU emulation)"?
QEMU user-mode emulation is not installed on the host system (most common on Linux servers) binfmt_misc handlers are not registered for the target architecture The container image architecture doesn't match the host and no emulation is available
Is the "exec format error (using QEMU emulation)" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading