# 执行 /usr/bin/node：执行格式错误

- **ID:** `docker/exec-format-error-amd64-arm64`
- **领域:** docker
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

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

## 版本兼容性

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

## 解决方案

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

## 无效尝试

- **Reinstalling Node.js in the Dockerfile using apt-get install nodejs** — The error is not about missing Node.js but about architecture mismatch; reinstalling the same architecture package yields the same issue. (90% 失败率)
- **Adding 'RUN chmod +x /usr/bin/node' to the Dockerfile** — The file already has execute permissions; the error is due to the ELF binary being compiled for a different CPU architecture, not permission issues. (95% 失败率)
- **Setting 'FROM node:16' instead of 'FROM node:16-alpine'** — Both variants may default to the same architecture unless explicitly tagged; the tag change does not fix the architecture mismatch. (60% 失败率)
