期望行为:我可以使用苹果M1芯片构建的容器运行。
观察到的行为:
假设你拥有Google Cloud Run帐户并且可以将Docker镜像推送到Google Container Registry。在本示例中,我使用https://github.com/seenickcode/trivial-go-api。
- `git clone 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 Cloud Run > 创建新服务 > 选择所有默认选项的已推送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
我正在构建镜像的系统详细信息:
- 操作系统:macOS 11.2.3
- 芯片:Apple M1
- Docker版本:Docker Desktop for macOS v3.3.0 (62345)
重要提示:
- 当我使用其他架构时,例如通过Google容器构建或我的家用Windows(WSL)桌面,这一切都完全正常。
- 在使用苹果M1芯片构建的其他代码库中也存在此问题,例如我编写的另一个Rust项目和Dart。似乎与语言无关。
- 我已经使用Google Cloud Run多年了,在使用搭载苹果M1芯片的新笔记本电脑时出现了这个问题。