预期行为:我可以运行我使用 Apple M1 芯片构建的容器。
观察到的行为:
假设您有一个 Google Cloud Run 帐户并且可以将 Docker 镜像推送到 Google Container Registry。我在此示例中使用 https://github.com/seenickcode/trivial-go-api。
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
有关我在何处构建映像的系统详细信息:
重要说明:
答案 0 :(得分:0)
您正在构建 Google Cloud 不支持的 ARM 兼容映像。
我在将 Mac M1 构建的映像推送到 Heroku 时遇到了类似的问题,我使用 buildx
并设置了预期平台解决了该问题
docker buildx build --platform linux/amd64 -t myapp .
我写了一篇 Medium 帖子来解释问题并提出 2 个解决方案。
<块引用>Docker 设计为多平台,可以在不同的架构上运行,但是,镜像必须与它们将运行的平台相匹配。这不是我们的情况。