Docker: "exec /bin/sh: Exec Format Error" — Wrong Architecture Image

The image's CPU architecture doesn't match the host: amd64 image pulled on an ARM64 machine (or the reverse). Multi-platform builds with buildx are the durable fix; --platform is the quick one.

What you'll see

Root causes

Single-arch image on a mismatched host

The image was built/pulled for x86-64 but runs on arm64. Docker pulls the best-matching tag by default — if only amd64 exists, an ARM host still gets it, and the kernel can't execute those binaries. docker image inspect <img> --format '{{.Architecture}}' confirms in seconds.

FROM scratch or copied binaries with the wrong target

Scratch-based Go/Rust images that copied an amd64 binary into an otherwise-unspecified image: the manifest says unknown, the binary is amd64, the ARM host refuses. Same error, build-side origin.

Fix it

  1. Check the image architecture vs your host
    docker image inspect <image> --format '{{.Architecture}}' ; uname -m
  2. Quick fix: request the right platform explicitly
    docker run --platform linux/amd64 <image>   # via Rosetta/QEMU emulation on Apple Silicon — slower but runs
  3. Durable fix: build multi-arch images
    docker buildx build --platform linux/amd64,linux/arm64 -t <user>/<image>:tag --push .
  4. Compose: pin the platform per service while migrating
    # service: platform: linux/amd64   # until multi-arch images exist for that dependency

Field note

exec format error at STARTUP (before any app logs) is architecture almost by definition: the kernel literally can't parse the first instruction. App-level errors come after init begins. QEMU emulation (Docker Desktop's Rosetta setting) makes amd64-on-ARM work but costs performance — fine for a dev dependency, wrong answer for a server workload.

Common questions

Why does it work on my Intel machine but not my M-series Mac?

Same image bytes, different CPU: the amd64 binaries execute on Intel, fail on ARM. The image needs a matching architecture build — check with docker image inspect before anything else.

Doesn't Docker pick the right image automatically?

Only if the repository publishes multi-arch manifests. For single-arch images, the pull succeeds anyway and the failure happens at run: exec format error is that exact moment.

Ship it right the first time

A production-shaped compose stack: healthchecks, resource limits, log rotation. Never debug a boot race again.

Docker Production Starter — $19 →

One-time. Yours to modify. Instant download from the NinjaOps template store.