[英]"exec format error" when running containers build with Apple M1 Chip (ARM based systems)
Expected behavior: I can run a container I've built using an Apple M1 chip.预期行为:我可以运行使用 Apple M1 芯片构建的容器。
Observed behavior:观察到的行为:
Assuming you have a Google Cloud Run account and can push Docker images to Google Container Registry.假设您有一个 Google Cloud Run 帐户并且可以将 Docker 图像推送到 Google Container Registry。 I'm using https://github.com/seenickcode/trivial-go-api for this example.我在这个例子中使用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 > Create new service > select your pushed Docker image with all default options > Run Go to console.cloud.google.com
, Google Cloud Run > Create new service > select your pushed Docker image with all default options > RunCloud 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.
Logs:日志:
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
System details on where I'm building my image:关于我在哪里构建图像的系统详细信息:
Important Notes:重要笔记:
You are building an ARM-compatible image which Google Cloud does not support.您正在构建 Google Cloud 不支持的与 ARM 兼容的映像。
I have hit a similar problem pushing my Mac M1 built image to Heroku, which I solved using buildx
and setting the expected platform我遇到了类似的问题,将我的 Mac M1 构建映像推送到 Heroku,我使用buildx
解决了这个问题并设置了预期的平台
docker buildx build --platform linux/amd64 -t myapp .
I have written a Medium post to explain the problem and propose 2 solutions.我写了一篇Medium帖子来解释这个问题并提出 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. Docker 在设计上是多平台的,可以在不同的架构上运行,但是,图像必须与它们将运行的平台相匹配。 Which is not our case.这不是我们的情况。
Also you can build x86 compatible image and push to artifact registry with single command:您还可以构建 x86 兼容映像并使用单个命令推送到工件注册表:
docker buildx build \
--platform linux/amd64 \
--push \
-t us-central1-docker.pkg.dev/your_project/your_registry/myapp .
As from docker API version 1.40 , you can specify the platform upon which your image needs to be built by using the --platform
option, without using buildx.从 docker API 版本 1.40开始,您可以使用--platform
选项指定构建镜像的平台,而无需使用 buildx。
docker build --platform=linux/amd64 -t myapp .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.