"exec format error" 当 运行 容器使用 Apple M1 芯片构建时(基于 ARM 的系统)
"exec format error" when running containers build with Apple M1 Chip (ARM based systems)
预期行为:我可以 运行 我使用 Apple M1 芯片构建的容器。
观察到的行为:
假设您有一个 Google Cloud 运行 帐户并且可以将 Docker 图像推送到 Google Container Registry。我在这个例子中使用 https://github.com/seenickcode/trivial-go-api。
- `git 克隆 git@github.com:seenickcode/trivial-go-api.git'
cd trivial-go-api
docker build -t gcr.io/<YOUR GCR PROJECT ID>/example .
docker push -t gcr.io/<YOUR GCR PROJECT ID>/example
- 转到
console.cloud.google.com
、Google 云 运行 > 创建新服务 > select 你推送的 Docker 图像所有默认选项 > 运行
- 显示错误:
Cloud Run error: Container failed to start.
Failed to start and then listen on the port defined by the PORT environment variable.
Logs for this revision might contain more information.
日志:
2021-04-02 09:35:40.045 EDT
Cloud Run ReplaceService example hello@redactedforso.com {@type: type.googleapis.com/google.cloud.audit.AuditLog, authenticationInfo: {…}, authorizationInfo: […], methodName: google.cloud.run.v1.Services.ReplaceService, request: {…}, requestMetadata: {…}, resourceLocation: {…}, resourceName: namespaces/myprojectforso-282419/services/example, response: {…}, servi…
Error
2021-04-02 09:35:49.034 EDT
terminated: Application failed to start: Failed to create init process: failed to load /app/main: exec format error
Warning
2021-04-02 09:35:49.174 EDT
Application exec likely failed
Notice
2021-04-02 09:57:43.102 EDT
Cloud Run ReplaceService example hello@redactedforso.com {@type: type.googleapis.com/google.cloud.audit.AuditLog, authenticationInfo: {…}, authorizationInfo: […], methodName: google.cloud.run.v1.Services.ReplaceService, request: {…}, requestMetadata: {…}, resourceLocation: {…}, resourceName: namespaces/myprojectforso-282419/services/example, response: {…}, servi…
Error
2021-04-02 09:57:50.657 EDT
terminated: Application failed to start: Failed to create init process: failed to load /app/main: exec format error
有关我在哪里构建图像的系统详细信息:
- OS: macOS 11.2.3
- 芯片:Apple M1
- Docker 版本:Docker Desktop for macOS v3.3.0 (62345)
重要提示:
- 当我使用另一种架构时,这对我来说完全没问题,即通过 Google Container Build 或我家的 Windows (WSL) 桌面。
- 当使用 Apple M1 芯片构建时,这也不适用于其他代码库,例如我用 Rust 和 Dart 编写的另一个项目。似乎与语言无关。
- 我已经使用 Google Cloud 运行 多年了,当我使用配备 Apple M1 芯片的新笔记本电脑时,这个问题突然出现了。
您正在构建 Google 云不支持的 ARM 兼容映像。
我在将我的 Mac M1 构建映像推送到 Heroku 时遇到了类似的问题,我使用 buildx
并设置了预期的平台
解决了这个问题
docker buildx build --platform linux/amd64 -t myapp .
我写了一个Mediumpost来说明问题,提出2个解决方案。
Docker is by design multi-platform and can run on different architectures, however, the images must match the platform they will be run on. Which is not our case.
预期行为:我可以 运行 我使用 Apple M1 芯片构建的容器。
观察到的行为:
假设您有一个 Google Cloud 运行 帐户并且可以将 Docker 图像推送到 Google Container Registry。我在这个例子中使用 https://github.com/seenickcode/trivial-go-api。
- `git 克隆 git@github.com:seenickcode/trivial-go-api.git'
cd trivial-go-api
docker build -t gcr.io/<YOUR GCR PROJECT ID>/example .
docker push -t gcr.io/<YOUR GCR PROJECT ID>/example
- 转到
console.cloud.google.com
、Google 云 运行 > 创建新服务 > select 你推送的 Docker 图像所有默认选项 > 运行 - 显示错误:
Cloud Run error: Container failed to start.
Failed to start and then listen on the port defined by the PORT environment variable.
Logs for this revision might contain more information.
日志:
2021-04-02 09:35:40.045 EDT
Cloud Run ReplaceService example hello@redactedforso.com {@type: type.googleapis.com/google.cloud.audit.AuditLog, authenticationInfo: {…}, authorizationInfo: […], methodName: google.cloud.run.v1.Services.ReplaceService, request: {…}, requestMetadata: {…}, resourceLocation: {…}, resourceName: namespaces/myprojectforso-282419/services/example, response: {…}, servi…
Error
2021-04-02 09:35:49.034 EDT
terminated: Application failed to start: Failed to create init process: failed to load /app/main: exec format error
Warning
2021-04-02 09:35:49.174 EDT
Application exec likely failed
Notice
2021-04-02 09:57:43.102 EDT
Cloud Run ReplaceService example hello@redactedforso.com {@type: type.googleapis.com/google.cloud.audit.AuditLog, authenticationInfo: {…}, authorizationInfo: […], methodName: google.cloud.run.v1.Services.ReplaceService, request: {…}, requestMetadata: {…}, resourceLocation: {…}, resourceName: namespaces/myprojectforso-282419/services/example, response: {…}, servi…
Error
2021-04-02 09:57:50.657 EDT
terminated: Application failed to start: Failed to create init process: failed to load /app/main: exec format error
有关我在哪里构建图像的系统详细信息:
- OS: macOS 11.2.3
- 芯片:Apple M1
- Docker 版本:Docker Desktop for macOS v3.3.0 (62345)
重要提示:
- 当我使用另一种架构时,这对我来说完全没问题,即通过 Google Container Build 或我家的 Windows (WSL) 桌面。
- 当使用 Apple M1 芯片构建时,这也不适用于其他代码库,例如我用 Rust 和 Dart 编写的另一个项目。似乎与语言无关。
- 我已经使用 Google Cloud 运行 多年了,当我使用配备 Apple M1 芯片的新笔记本电脑时,这个问题突然出现了。
您正在构建 Google 云不支持的 ARM 兼容映像。
我在将我的 Mac M1 构建映像推送到 Heroku 时遇到了类似的问题,我使用 buildx
并设置了预期的平台
docker buildx build --platform linux/amd64 -t myapp .
我写了一个Mediumpost来说明问题,提出2个解决方案。
Docker is by design multi-platform and can run on different architectures, however, the images must match the platform they will be run on. Which is not our case.