Skip to content
FR
  1. LuzineDebug
  2. Docker & DevOps
  3. exec /usr/local/bin/docker-entrypoint.sh: exec f…
Docker & DevOps Intermediate ≈ 15 min to fix

Fix "exec format error" in Docker (arm64 / amd64)

Error message
exec /usr/local/bin/docker-entrypoint.sh: exec format error
  • standard_init_linux.go:228: exec user process caused: exec format error
  • exec /app/server: exec format error
  • WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
  • exec /bin/sh: exec format error
In short

The kernel cannot execute the launched file: most often the image was built for another architecture (arm64 on an Apple Silicon Mac, deployed to an amd64 server). Rebuild for the right platform with docker buildx build --platform linux/amd64, or fix the entrypoint script’s shebang.

Be the first to confirm this fix

What this error means

When the container starts, the runtime calls execve() on the entrypoint. The kernel reads the file header: an ELF binary must match the CPU (x86-64 or AArch64), and a script must start exactly with #! followed by an interpreter. If the binary targets another architecture and no QEMU emulation is registered, or if the script has no valid shebang (missing line, UTF-8 BOM before #!), the kernel returns ENOEXEC, shown as "exec format error". The container exits immediately with code 1 or 255.

Common causes

  1. Image built on Apple Silicon (arm64) then run on an x86-64 (amd64) server or CI runner, or the other way round.
  2. Binary downloaded or compiled for the wrong architecture in the Dockerfile (hard-coded linux-amd64 URL, fixed GOARCH).
  3. Script without a shebang or with a BOM: docker-entrypoint.sh does not start with #!/bin/sh, or the editor added an invisible UTF-8 BOM before it.
  4. No emulation on Linux: --platform linux/arm64 on an amd64 host without QEMU/binfmt registered.

Step-by-step fix

  1. Compare image and host architecture

    uname -m prints x86_64 (amd64) or aarch64/arm64. If the image shows another architecture, that is the cause.

    bash
    uname -m
    docker image inspect --format '{{.Os}}/{{.Architecture}}' myapp:latest
  2. Build for the target platform

    On an Apple Silicon Mac, target the server explicitly. For an image that runs everywhere, build both architectures and push a multi-platform manifest.

    bash
    docker buildx build --platform linux/amd64 -t myapp:latest --load .
    
    docker buildx build --platform linux/amd64,linux/arm64 \
      -t registry.example.com/myapp:1.0 --push .
  3. Make the Dockerfile architecture-independent

    Use the TARGETARCH variable provided by BuildKit (amd64, arm64) instead of a hard-coded architecture for downloaded or compiled binaries.

    dockerfile
    FROM --platform=$BUILDPLATFORM golang:1.23 AS build
    ARG TARGETOS TARGETARCH
    WORKDIR /src
    COPY . .
    RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/server .
    
    FROM alpine:3.20
    COPY --from=build /out/server /usr/local/bin/server
    ENTRYPOINT ["/usr/local/bin/server"]
  4. Run a foreign image with emulation

    To run an amd64 image on arm64 (or the reverse), specify the platform. Docker Desktop already emulates; on Linux, register QEMU once (privileged command, run it on a trusted machine).

    bash
    docker run --privileged --rm tonistiigi/binfmt --install all
    docker run --rm --platform linux/amd64 myapp:latest
  5. Check the script’s shebang and encoding

    The file command reports a BOM ("with BOM") or CRLF line endings. The first line must be exactly #!/bin/sh or #!/usr/bin/env bash. Note: a CRLF shebang usually gives "no such file or directory" instead, but is fixed the same way.

    bash
    file docker-entrypoint.sh
    head -n 1 docker-entrypoint.sh | od -c | head -n 2
  6. Clean the script in the image

    Strip the BOM and CRLF at build time and make the script executable. Also add a .gitattributes rule so Git on Windows does not bring CRLF back.

    dockerfile
    COPY docker-entrypoint.sh /usr/local/bin/
    RUN sed -i -e '1s/^\xEF\xBB\xBF//' -e 's/\r$//' /usr/local/bin/docker-entrypoint.sh \
     && chmod +x /usr/local/bin/docker-entrypoint.sh
    # .gitattributes:  *.sh text eol=lf

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Pin the platform in compose.yaml (platform: linux/amd64) or always build multi-platform in CI.
  • Use TARGETARCH in Dockerfiles and choose multi-architecture base images (official images).
  • Add *.sh text eol=lf to .gitattributes and set the editor to UTF-8 without BOM.

Frequently asked questions

Why does my image work on my M1/M2/M3 Mac but not on the server?

It was built as arm64, the Mac’s architecture. The server is amd64 and cannot run it without emulation. Rebuild with --platform linux/amd64 or multi-platform.

How do I know which architecture a binary is compiled for?

Use file ./binary: it prints for example "ELF 64-bit LSB executable, x86-64" or "ARM aarch64".

Is QEMU emulation good enough in production?

It works but is much slower and sometimes unstable. In production, use an image native to the server’s architecture.

Useful tools for this error

More Docker & DevOps errors

All Docker & DevOps errors →