Google Cloud Run — Deploying Containerized Applications to a Serverless Environment ⚡

Cloud Run is a managed compute platform that enables you to run stateless containers.

Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most — building great applications.

It is built from Knative, letting you choose to run your containers either fully managed with Cloud Run, or in your Google Kubernetes Engine cluster with Cloud Run on GKE.

In this article, we would:

  1. Setup Cloud Shell
  2. Demo Project files and Dockerfile
  3. Build our Docker Image with Cloud Build and Push to Google Container Registry
  4. Deploy to Cloud Run from Google Container Registry using both Google Cloud Shell and Container Registry Interface

Setup Cloud Shell

I will be using Google Cloud Shell to manage resources on Google Cloud Platform with an assumption that you have it installed on your PC.

gcloud auth login
gcloud config set project <PROJECT_ID>
gcloud config set compute/zone us-central1-f
gcloud services enable run.googleapis.com
gcloud components install beta

where <PROJECT_ID> is your GCP project ID.

Demo Project files and Dockerfile

Our demo project files for this article would just be index.js and package.json. We'll also have a Dockerfile to build our image.

Demo Project Files on GitHub

Feel free to use your own project files.

We would not be building our Docker image on our PC, Google Cloud Build allows us to build a Docker image using a Dockerfile, which we already have and then pushes the image to Container Registry 😊

Build Docker Image with Cloud Build and Push to Google Container Registry

Let’s use Google Cloud Build to build our Docker image and push the image to Container Registry. Both can be done by simply running the following command:

gcloud builds submit --tag gcr.io/[PROJECT_ID]/quickstart-image .

That’s it! We have our Docker image built and now on Container Registry.

Docker Image on Container Registry

Note that if you’re building larger images, you can pass a timeout parameter such as: _--timeout=600s_

Deploy to Cloud Run from Google Container Registry

We could either deploy from Cloud Shell or directly from Container Registry Interface.

Deploying from Cloud Shell

gcloud beta run deploy --image gcr.io/<PROJECT-ID>/quickstart-image

We’ll be asked to input Service name and some other options. On success, you’ll get the Service URL 😀

Deploying from Container Registry Interface

Click on the Image Name and Deploy the latest by selecting Deploy to Cloud Run on the list of options.

Deploy to Cloud Run

We’ll also need to define the Service name and authentication option.

Create Service

Cloud Run also allows us define additional options for our deployment such as Environment Variables , Memory Allocation.

Additional Options for Cloud Run

Click Create and take a sip of that juice. Voila! Our Containerized Application Runs on Cloud Run - Serverlessly 😀

https://app-nchqhrxakq-uc.a.run.apphttps://app-nchqhrxakq-uc.a.run.app

Cloud Run does not charge when the service is not in use. You can use a custom domain rather than the default address that Cloud Run provides for a deployed service.


Cloud Run also runs on Google Kubernetes Engine — this gives you more flexibility on managing your infrastructure. The tweet below gives more insights on this.

Additional Resources on Cloud Run :: 📚 Cloud Run Product Overview 📯 Cloud Run Release Blog Post 📹 Cloud Run Launch Next 19 💻 Awesome Cloud RunCloud Events ☁️ KNative

Thanks for reading through! Let me know if I missed any step, if something didn’t work out quite right for you or if this guide was helpful.

Originally posted on Mercurie Blog

Timothy Olaleke

Learn how to use Google Cloud Platform services by following tutorials on #FullStackGCP.

Write your comment…

Be the first one to comment