Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to use Google Cloud Run when my Docker images are built on an ARM device?

I am having trouble deploying a Python FastAPI API in a Docker image to a cloud instance. I am using an M1 Mac, which has an ARM architecture. From what I know, Google Cloud Run instances are built on Linux machines with x86_64 architecture, so my container fails to deploy.

I have seen two solutions to this problem, but both have drawbacks. The first solution is to use the -platform flag when building my Docker image. This will build an image for a different architecture, but it will also make the image very large (my image is normally approx. 200MB but building for a different platform makes it 5+ GB) and take a long time to build (almost 20 minutes). This is not practical or portable, and it would be difficult to implement into a CI/CD pipeline. It should be noted that my API has some heavy Python dependencies like PyTorch, so it is already large from that standpoint.

The second solution is to use Google Compute Engine (GCE) instead of Google Cloud Run. GCE allows me to specify the architecture of the virtual machine instance, so I could choose an ARM instance. However, using an ARM instance like the TAU line with GCE requires me to use Google Kubernetes Engine (GKE). GKE is designed for multi-container workloads, and it would be very expensive to use for a single-container API.

I am looking for a solution to this problem. I would like to be able to deploy my API to Google Cloud without having to use a large, slow container or an expensive GKE cluster.

Thank you for your time and attention to this matter.

First, I tried deploying an ARM-built Docker image on Cloud Run. This failed as the instance could not find the required binaries. Then, I used docker build --platform linux/amd64 and also tried the same with docker buildx build... but, like i mentioned above, these take ages and create massive images.

As for GCE and GKE, I just browsed the deployment page on the Cloud Console looking for solutions.

1 2 5,026
2 REPLIES 2

Given your requirements and constraints, you may want to look into Google App Engine.

Google App Engine offers a fully managed serverless platform that automatically handles the deployment, scaling, and management of applications. It allows you to focus on writing code without worrying about the underlying infrastructure.

During the deployment process, Google App Engine will automatically handle the necessary configurations and optimizations for running your application on the appropriate platform (x86_64 in this case).

By using GAE, you can avoid the complexities of managing Kubernetes clusters and the need to build multi-platform Docker images. It is also a cost-effective option as it scales automatically based on demand, and you only pay for the resources used. Keep in mind that at the time of your deployment, the version of Python and other runtime options may have been updated, so it's essential to refer to the official Google App Engine documentation for the latest specifications.

glen_yu
Google Developer Expert
Google Developer Expert

Have you tried multi-platform builds?