exec format error 🐳 Docker

exec /usr/local/bin/docker-entrypoint.sh: exec format error

The container tried to run a binary built for a different CPU architecture (arm64 vs amd64) — or a script with a broken shebang / Windows line endings.

Seen on: Docker Kubernetes Linux

Meaning

Images built on Apple Silicon (arm64) and run on x86_64 servers (or the reverse) fail instantly with this error, often showing up as CrashLoopBackOff in Kubernetes. The other common source is an entrypoint script saved with CRLF line endings or without a #!/bin/sh line.

Common causes

  • Image built for arm64 (M1/M2/M3 Mac) running on amd64 servers, or vice versa
  • Base image tag only published for one architecture
  • Entrypoint script with Windows CRLF line endings
  • Missing shebang (#!/bin/sh) at the top of the script

⚡ Quick fix

  1. Check architectures: docker image inspect <img> --format '{{.Architecture}}' vs uname -m on the host
  2. Build for the target platform: docker buildx build --platform linux/amd64
  3. Convert scripts to LF (dos2unix entrypoint.sh) and add a shebang

Detailed fix by platform

Docker

  1. Build multi-arch images:
    bash
    docker buildx create --use
    docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/acme/api:1.4 --push .
  2. Normalise line endings in the image build:
    dockerfile
    COPY docker-entrypoint.sh /usr/local/bin/
    RUN sed -i 's/\r$//' /usr/local/bin/docker-entrypoint.sh && chmod +x /usr/local/bin/docker-entrypoint.sh

How to diagnose

  1. Architecture — Image arch vs host arch?
  2. Script — Shebang present? CRLF line endings?
  3. Base image — Is the tag published for your platform?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.