docker type_error ai_generated true

执行 /usr/bin/node:执行格式错误

exec /usr/bin/node: exec format error

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

其他格式: JSON · Markdown 中文 · English
95%修复率
90%置信度
1证据数
2023-03-08首次发现

版本兼容性

版本状态引入弃用备注
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

根因分析

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

English

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

官方文档

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

解决方案

  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'。

无效尝试

常见但无效的做法:

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

    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% 失败

    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% 失败

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