docker type_error ai_generated true

exec /usr/bin/node: exec format error

ID: docker/exec-format-error-amd64-arm64

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2023-03-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Docker 24.0.5 active — — —
Docker Desktop 4.22.0 active — — —
Node.js 16.20.0 active — — —
ARM64 Ubuntu 22.04 active — — —
AMD64 Debian 11 active — — —

Root Cause

Pulling an AMD64 image on an ARM64 host (or vice versa) without using multi-arch support results in a binary that the host CPU cannot execute.

generic

中文

在 ARM64 主机上拉取 AMD64 镜像(反之亦然)且未使用多架构支持时,生成的二进制文件无法在主机 CPU 上执行。

Official Documentation

https://docs.docker.com/build/building/multi-platform/

Workarounds

  1. 95% success Specify the platform explicitly in docker run: 'docker run --platform linux/arm64 node:16' on an ARM64 host, or '--platform linux/amd64' on AMD64.
    Specify the platform explicitly in docker run: 'docker run --platform linux/arm64 node:16' on an ARM64 host, or '--platform linux/amd64' on AMD64.
  2. 90% success Use Docker Buildx to build for multiple architectures: 'docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest .'
    Use Docker Buildx to build for multiple architectures: 'docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest .'
  3. 85% success Pull a multi-arch manifest by using the official image that supports both architectures, e.g., 'FROM --platform=$BUILDPLATFORM node:16' in your Dockerfile.
    Pull a multi-arch manifest by using the official image that supports both architectures, e.g., 'FROM --platform=$BUILDPLATFORM node:16' in your Dockerfile.

中文步骤

  1. 在 docker run 中显式指定平台:在 ARM64 主机上使用 'docker run --platform linux/arm64 node:16',或在 AMD64 上使用 '--platform linux/amd64'。
  2. 使用 Docker Buildx 构建多架构镜像:'docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest .'
  3. 拉取支持多架构的官方镜像的 manifest,例如在 Dockerfile 中使用 'FROM --platform=$BUILDPLATFORM node:16'。

Dead Ends

Common approaches that don't work:

  1. Reinstalling Node.js in the Dockerfile using apt-get install nodejs 90% fail

    The error is not about missing Node.js but about architecture mismatch; reinstalling the same architecture package yields the same issue.

  2. Adding 'RUN chmod +x /usr/bin/node' to the Dockerfile 95% fail

    The file already has execute permissions; the error is due to the ELF binary being compiled for a different CPU architecture, not permission issues.

  3. Setting 'FROM node:16' instead of 'FROM node:16-alpine' 60% fail

    Both variants may default to the same architecture unless explicitly tagged; the tag change does not fix the architecture mismatch.