---
title: "How to Deploy Scalable Containerized Apps With GCP Cloud Run"
description: "Make your life as a container administrator easier with scalable containerized applications using the GCP Cloud Run platform!"
canonical: "https://adamtheautomator.com/gcp-cloud-run/"
---

# How to Deploy Scalable Containerized Apps With GCP Cloud Run

> Make your life as a container administrator easier with scalable containerized applications using the GCP Cloud Run platform!

Source: https://adamtheautomator.com/gcp-cloud-run/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Deploy Scalable Containerized Apps With GCP Cloud Run](https://adamtheautomator.com/wp-content/uploads/2022/12/gcp-cloud-run.jpg)

# How to Deploy Scalable Containerized Apps With GCP Cloud Run

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)14 December 20227 min. read

Categories: [DevOps](/category/devops/)

Tags:[Google Cloud](/tag/google-cloud/)

Table of Contents

*   [Prerequisite](#prerequisite)
*   [Creating a GCP Project](#creating-a-gcp-project)
*   [Enabling the Cloud Run API](#enabling-the-cloud-run-api)
*   [Preparing a Node.js App for GCP Cloud Run Jobs](#preparing-a-nodejs-app-for-gcp-cloud-run-jobs)
*   [Containerizing and Uploading Application to Artifact Registry](#containerizing-and-uploading-application-to-artifact-registry)
*   [Deploying the Container Image to GCP Cloud Run](#deploying-the-container-image-to-gcp-cloud-run)
*   [Conclusion](#conclusion)

Running applications in a stable and scalable way can be challenging. Fortunately, Google Cloud Platform (GCP) offers GCP Cloud Run that allows users to deploy and manage scalable, containerized applications.

The complexity of managing resources, hosting them in multiple environments, and dealing with potential service outages can cause headaches for developers. But worry not! This tutorial will walk you through how to deploy a basic scalable containerized application using GCP Cloud Run.

Ready? Read on to up your app ops game!

Cloud Run tutorials move quickly from containers to deployment decisions. If you want a structured path through cloud deployment fundamentals, [compare cloud deployment courses on Udemy](https://trk.udemy.com/c/1454808/3193860/39854) before you buy.

## Prerequisite

This tutorial will be a hands-on demonstration. To follow along, ensure you have a GCP account with active billing enabled, but a [free trial account](https://cloud.google.com/free) is sufficient.

## Creating a GCP Project

The first step in containerizing your application in GCP is to create a new GCP project. Projects are the logical way to organize resources across GCP. Each project provides an isolated environment in which all your services and resources are contained.

> _Note that you should not mix resources from existing projects, which also helps when you clean up your environment later on._

To create a GCP project, follow these steps:

1\. Open your favorite web browser, and navigate to the [**Manage resources**](https://console.cloud.google.com/cloud-resource-manager) page in the Google Cloud Console.

2\. Next, click **CREATE PROJECT** to initiate creating a new project.

![Initiating creating a new project](https://adamtheautomator.com/wp-content/uploads/2022/12/image-18.png)

Initiating creating a new project

On the next screen, provide the following for your project: Project name A unique name for your GCP project (i.e., gcp-cloud-run-project). Location An appropriate organization if you have one; otherwise, skip this field.

<table><tbody><tr><td>Project name</td><td>A unique name for your GCP project (i.e., gcp-cloud-run-project).</td></tr><tr><td>Location</td><td>An appropriate organization if you have one; otherwise, skip this field.</td></tr></tbody></table>

Once filled up, click **CREATE** to create the project.

![Creating a project ](https://adamtheautomator.com/wp-content/uploads/2022/12/image-57.png)

Creating a project

A confirmation message, as shown below, indicates a new project has been created.

![Confirming the project has been created](https://adamtheautomator.com/wp-content/uploads/2022/12/image-58.png)

Confirming the project has been created

4\. Now, navigate to the [project selector](https://console.cloud.google.com/projectselector2/home/dashboard) page, and select your newly-created project to set it as the current/active project/

![Selecting the newly created project](https://adamtheautomator.com/wp-content/uploads/2022/12/image-59.png)

Selecting the newly created project

## Enabling the Cloud Run API

Before you deploy your containerized application, you will need to enable the Cloud Run API first. How? Google Cloud provides a feature called Google Cloud Shell, a web-based shell environment where you can manage your GCP resources.

In this tutorial, you will use Google Cloud Shell for running commands and interacting with Cloud Run and other GCP services.

1\. Click the Activate Cloud Shell icon (upper-right) to activate the Google Cloud Shell. A shell terminal appears at the bottom of your screen, as shown below.

![Activating Google Cloud Shell](https://adamtheautomator.com/wp-content/uploads/2022/12/image-60.png)

Activating Google Cloud Shell

2\. Next, run the below [`gcloud auth list`](https://cloud.google.com/sdk/gcloud/reference/auth/list) command to confirm that your Google Cloud account is authenticated and active.

```bash
gcloud auth list
```

Click **AUTHORIZE** when prompted to authorize gcloud to access your Google Cloud account.

Related:[How to Perform a gcloud CLI Install and Manage Google Cloud](https://adamtheautomator.com/gcloud-cli-install/)

![Authorizing gcloud ](https://adamtheautomator.com/wp-content/uploads/2022/12/image-61.png)

Authorizing gcloud

Once authenticated, you will see a similar output as below.

![Confirming authorization is successful](https://adamtheautomator.com/wp-content/uploads/2022/12/image-62.png)

Confirming authorization is successful

3\. Now, run the following [`gcloud config list`](https://cloud.google.com/sdk/gcloud/reference/config/list) command to verify that the project you created is set as your current project.

```bash
gcloud config list project
```

![Verifying the currently active project](https://adamtheautomator.com/wp-content/uploads/2022/12/image-63.png)

Verifying the currently active project

4\. Once your project is verified, run the below [`gcloud config set`](https://cloud.google.com/sdk/gcloud/reference/config/set) command to set the region where you want to deploy the application. The region is default set to us-central1 but can be changed as needed.

```bash
gcloud config set compute/region us-central1
```

![Setting the region for application deployment](https://adamtheautomator.com/wp-content/uploads/2022/12/image-64.png)

Setting the region for application deployment

5\. Lastly, run the [`gcloud service enable`](https://cloud.google.com/sdk/gcloud/reference/services/enable) command to enable Cloud Run API (`run.googleapis.com`).

```bash
gcloud services enable run.googleapis.com
```

![Enabling the Cloud Run API](https://adamtheautomator.com/wp-content/uploads/2022/12/image-65.png)

Enabling the Cloud Run API

## Preparing a Node.js App for GCP Cloud Run Jobs

Now that your environment is set up, preparing a sample application you can deploy using Cloud Run is the next step.

In this tutorial, you will deploy a basic [Node.js](https://adamtheautomator.com/https-nodejs/) “Hello World” application powered by the Express web framework. This app returns a simple “Hello World!” response triggered by an HTTP request.

Related:[How to Create an HTTPS NodeJS Web Service with Express](https://adamtheautomator.com/https-nodejs/)

1\. Run the below commands, which do not provide output, but create a new directory name `helloworld` and move into that directory. This directory will hold your source code and other files related to the application.

```bash
mkdir helloworld && cd helloworld
```

2\. Next, create a _package.json_ file in your preferred editor. This file defines the dependencies for your Node.js application.

```bash
nano package.json
```

Add the following code to the _package.json_ file, and save the changes. This file defines the project name, version, and description and gives instructions on how to start the application.

```bash
{
  "name": "helloworld",
  "description": "Sample hello world app in Nodejs",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "author": "Google LLC",
  "license": "Apache-2.0",
  "dependencies": {
    "express": "^4.17.1"
  }
}
```

3\. Create another file called _index.js_ file. This file contains the main source code for your Node.js application, placed in the same directory (_helloworld_) as the _package.json_ file.

```bash
nano index.js 
```

Add the below code to the _index.js_ file and save the changes. This code is responsible for setting up the Express web server. At the same time, this code defines a single route that will return a “Hello World!” response with the `PORT` environment variable.

Related:[PowerShell Environment Variables: The Ultimate Guide](https://adamtheautomator.com/powershell-environment-variables/)

```bash
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
app.get('/', (req, res) => {
  const name = process.env.NAME || 'World';
  res.send(`Hello ${name}!`);
});
app.listen(port, () => {
  console.log(`helloworld: listening on port ${port}`);
});
```

## Containerizing and Uploading Application to Artifact Registry

Your sample application and necessary configuration files are ready. But you still need a place where you can manage container images.

The Google Cloud Artifact Registry is a single place to manage your container images and is fully integrated with Google Cloud’s tooling and runtimes.

> 💡 _The Artifact Registry comes with support for native artifact protocols. As a result, you can quickly integrate your application with your CI/CD tooling to set up automated pipelines._

Related:[How to Create a CI/CD Pipeline for CircleCI Docker Images](https://adamtheautomator.com/circleci-docker-images/)

1\. Create a Dockerfile in the same directory (_helloworld_) as your other files.

Related:[Using the Dockerfile ENTRYPOINT and CMD Instructions](https://adamtheautomator.com/dockerfile-entrypoint/)

```bash
nano Dockerfile
```

Add the below code to the Dockerfile and save the changes. This code specifies the configuration to build and run your Node.js application when executed in a container environment.

```bash
# Specifies the version of Node.js to use
FROM node:12-slim
# Sets the working directory for your application files,
WORKDIR /usr/src/app
# Copies your package information and source code
COPY package*.json ./
# Installs production dependencies
RUN npm install --only=production
# Copies your package information and source code
COPY . ./
Runs your Node.js application 
CMD [ "npm", "start" ]
```

Next, run the following [`gcloud builds submit`](https://cloud.google.com/sdk/gcloud/reference/builds/submit) command to containerize and upload your Node.js application to the Artifact Registry. Google Cloud Shell has pre-installed tools named [buildpack](https://cloud.google.com/blog/products/containers-kubernetes/google-cloud-now-supports-buildpacks), which simplifies this process.

> 💡 _The minimum number of containers is zero, while the upper limit is based on your GCP project’s quotas for Cloud Run. The default value is 1000 (usually enough for most use cases.), but you can increase this limit by submitting a request to GCP support._

```bash
gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld
```

Once built, you will see a success message like the one below, which confirms your container image has been uploaded successfully.

![Confirming the container image has been uploaded](https://adamtheautomator.com/wp-content/uploads/2022/12/image-66.png)

Confirming the container image has been uploaded

3\. Run the below [`gcloud container`](https://cloud.google.com/sdk/gcloud/reference/container) command to list your existing container images (`images list`) in the current project. `gcloud container images list`

```bash
gcloud container images list
```

As shown below, you will see the container image you created in step two.

![Listing all existing container images](https://adamtheautomator.com/wp-content/uploads/2022/12/image-67.png)

Listing all existing container images

4\. Now, execute the following [`docker run`](https://docs.docker.com/engine/reference/commandline/run/) command to run your Node.js application locally on port `8080`.

```bash
docker run -d -p 8080:8080 gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld
```

![Testing your Node.js application locally](https://adamtheautomator.com/wp-content/uploads/2022/12/image-68.png)

Testing your Node.js application locally

5\. Lastly, run the `curl` command below to test your application by making an HTTP request.

Related:[CURL Linux Command : Learning By Example](https://adamtheautomator.com/curl-linux/)

```bash
curl http://localhost:8080
```

If all goes well, you will see the **Hello World!** response, as shown below. This output confirms that your Node.js application works locally as expected in a containerized environment.

![Making an HTTP request](https://adamtheautomator.com/wp-content/uploads/2022/12/image-69.png)

Making an HTTP request

## Deploying the Container Image to GCP Cloud Run

Now that you have containerized and tested your Node.js application locally, you can deploy it to Cloud Run. Once deployed, you will later test your application deployment by accessing your deployment’s service URL via your web browser.

1\. Run the below [`gcloud run`](https://cloud.google.com/sdk/gcloud/reference/run) command to `deploy` your application on Cloud Run.

```bash
gcloud run deploy --image gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld --allow-unauthenticated --region=us-central1
```

Press Enter to accept the service name when prompted.

![Deploying the container image to GCP Cloud Run](https://adamtheautomator.com/wp-content/uploads/2022/12/image-70.png)

Deploying the container image to GCP Cloud Run

Wait until the deployment completes, and you will see a success message like the one below. This output confirms your application has been successfully deployed.

![Confirming the application deployment is successful](https://adamtheautomator.com/wp-content/uploads/2022/12/image-71.png)

Confirming the application deployment is successful

2\. Next, click the hamburger menu (top-left) and select **Cloud Run** to open the Cloud Run Dashboard.

![Accessing the Cloud Run dashboard](https://adamtheautomator.com/wp-content/uploads/2022/12/image-72.png)

Accessing the Cloud Run dashboard

3\. Click on your hyperlinked service name (**helloworld**). Doing so opens the **Service details** page, which provides details about the service, including its URL and domain mapping.

The green checkmark below indicates the service is running correctly.

> 💡 _Unlike a Compute Engine or a Virtual Machine (VM) instance, you will not be charged for the idle time of your application. Once either stops handling requests, Cloud Run will automatically shut down its containers with no additional cost._

Related:[How to Create a Google Virtual Machine](https://adamtheautomator.com/google-virtual-machine/)

![ Accessing the service](https://adamtheautomator.com/wp-content/uploads/2022/12/image-73.png)

Accessing the service

4\. Click on the copy icon to copy the URL on the **Service details** page, as shown below. This URL is what you will use to access your application.

![Copying the service URL](https://adamtheautomator.com/wp-content/uploads/2022/12/image-74.png)

Copying the service URL

5\. Now, navigate to the URL you copied in step four to a new browser tab to access your application, and you will see the **Hello World** message as a response.

This output below confirms your application is successfully deployed and running on Cloud Run, as shown below.

At this point, GCP Cloud Run will automatically scale up or down the number of containers running your application based on the traffic your application receives. No need to worry about manual scaling or administration overhead.

![Accessing the Node.js application in GCP Cloud Run](https://adamtheautomator.com/wp-content/uploads/2022/12/image-75.png)

Accessing the Node.js application in GCP Cloud Run

## Conclusion

Scalable containerized applications are an essential part of any modern infrastructure. And in this tutorial, you have learned how to use GCP Cloud Run to deploy and manage containerized applications at scale quickly.

With the GCP Cloud Run, you get maximum performance with minimal costs as you do not have to provide the underlying compute resources —- you only pay for what you use.

What you have learned in this tutorial is just the tip of the iceberg. Why not explore more and start [deploying a Python service to Cloud Run](https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-python-service)?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fgcp-cloud-run%2F&text=How%20to%20Deploy%20Scalable%20Containerized%20Apps%20With%20GCP%20Cloud%20Run)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fgcp-cloud-run%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fgcp-cloud-run%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/12/gcp-cloud-functions.jpg)

### [GCP Cloud Functions Customize Your Serverless Workflow](/gcp-cloud-functions/)

Learn how to build and deploy scalable, serverless applications using GCP Cloud Functions. This tutorial covers essential concepts and best practices for streamlined workflows.

![](https://adamtheautomator.com/wp-content/uploads/2023/01/google-cloud-storage-python.jpg)

### [How to Install & Use the Google Cloud Storage Python Client](/google-cloud-storage-python-client/)

Discover how to use the Google Cloud Storage Python client in your projects and make your DevOps pipelines work even better!

![](https://adamtheautomator.com/wp-content/uploads/2022/12/gsutil.jpg)

### [Learning the gsutil Command Through Examples](/gsutil/)

Discover the many uses of the gsutil command and learn through examples how to utilize this command-line tool to make your management job easier!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
