Expected behavior: I can run a container I've built using an Apple M1 chip.
Observed behavior:
Assuming you have a Google Cloud Run account and can push Docker images to Google Container Registry. I'm using https://github.com/seenickcode/trivial-go-api for this example.
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 > 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 [email protected] {@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 [email protected] {@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.
I have hit a similar problem pushing my Mac M1 built image to Heroku, which I solved using buildx
and setting the expected platform
docker buildx build --platform linux/amd64 -t myapp .
I have written a Medium post to explain the problem and propose 2 solutions.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With