Cloud Run

Software developers today can focus on building applications faster without having to bother about how their codes run on other environments, this is because containerization takes care of bundling applications along with their configuration and dependencies into an efficient way of running it across different environments.

Deploying Containers (Docker or Kubernetes) can also be a headache when you also have to take care of provisioning the underlying infrastructure, however, Google Cloud provides a way for you to deploy containerized applications to the cloud in a serverless fashion called Cloud Run, it abstracts away the underlying infrastructure, runs and auto-scales your stateless application automatically.

In this article, we’ll briefly build and deploy a containerized application and deploy to Cloud Run.

Before you begin:
- Set up a Google Cloud Account & Project
- Set up Google Cloud Shell or Download its SDK
- Clone your containerized application or copy my example


from flask import Flask, request

app = Flask(__name__)

@app.route("/", methods=["GET"])
def homepage():
    if request.method == "GET":
        return jsonify({"message": "Hello World!"})

PORT = int(os.environ.get("PORT", 8080))
if __name__ == '__main__':,host='',port=PORT)
# Dockerfile
FROM python:3.7-stretch
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD [""]
# requirements.txt

Build and Publish Container Images

Cloud Build allows us to build Docker images on the Cloud, all we need is our project files (which includes a Dockerfile).

The following command runs on Cloud Shell to build our Docker image and push the image to Container Registry.

gcloud builds submit --tag<PROJECT_ID>/demo-image .

Replace <PROJECT_ID> with your actual project ID value.

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

Deploy to Cloud Run

We would go-ahead to deploy our image from Cloud Shell using the following command:gcloud beta run deploy demo-app --image<PROJECT_ID>/demo-image --region us-central1 --platform managed --allow-unauthenticated --quiet

Boom! The application container has been deployed to Cloud Run.😀

Cloud Run is worth looking into by teams, it provides affordability, security, isolation, flexibility by allowing deployment to a Kubernetes cluster (Cloud Run for Anthos) and a lot more.

Here’s a short demo of how fast it is to deploy and access containers with Cloud Run.

Another short demo of deploying directly to Cloud Run from your Git repository using the Cloud Run Button.

Check out some more Additional Resources on Cloud Run :
📚 Cloud Run Product Overview
💻 Awesome Cloud Run
🙋 Cloud Run FAQ

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.