Learn how to use a single command to build and deploy a "Hello World" web application from a code sample to Google Cloud using Cloud Run.
By following the steps in this quickstart, Cloud Run automatically builds a Dockerfile for you when you deploy from source code. For more information on how the Python buildpack determines the default entrypoint for Cloud Run source deployments, see Build a Python application.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud initCreate or select a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace PROJECT_ID with a name for the Google Cloud project you are creating.
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace PROJECT_ID with your Google Cloud project name.
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Verify that billing is enabled for your Google Cloud project.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud initCreate or select a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace PROJECT_ID with a name for the Google Cloud project you are creating.
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace PROJECT_ID with your Google Cloud project name.
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Verify that billing is enabled for your Google Cloud project.
gcloud config set project PROJECT_ID
If you are under a domain restriction organization policy restricting unauthenticated invocations for your project, you will need to access your deployed service as described under Testing private services.
Enable the Cloud Run Admin API and Cloud Build APIs:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which contains the
serviceusage.services.enable permission. Learn how to grant
roles.
gcloud services enable run.googleapis.comcloudbuild.googleapis.com
After the Cloud Run Admin API is enabled, the Compute Engine default service account is automatically created.
To get the permissions that you need to complete this quickstart, ask your administrator to grant you the following IAM roles:
roles/run.admin)
on the projectroles/run.sourceDeveloper)
on the projectroles/iam.serviceAccountUser)
on the service identityroles/logging.viewer)
on the projectFor more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Cloud Build automatically uses the Compute Engine default service account as the default Cloud Build service account to build your source code and Cloud Run resource, unless you override this behavior.
For Cloud Build to build your sources, grant the Cloud Build service
account the Cloud Run
Builder
(roles/run.builder) role on your project:
gcloud projects add-iam-policy-binding PROJECT_ID \ --member=serviceAccount:SERVICE_ACCOUNT_EMAIL_ADDRESS \ --role=roles/run.builder
Replace PROJECT_ID with your Google Cloud
project ID and SERVICE_ACCOUNT_EMAIL_ADDRESS with the
email address of the Cloud Build service account. If you're using the
Compute Engine default service account as the Cloud Build service account, then
use the following format for the service account email address:
PROJECT_NUMBER-compute@developer.gserviceaccount.com
Replace PROJECT_NUMBER with your Google Cloud
project number.
For detailed instructions on how to find your project ID, and project number, see Creating and managing projects.
Granting the Cloud Run builder role takes a couple of minutes to propagate.
To write an application in Python:
Create a new directory named helloworld and change directory
into it:
mkdir helloworld
cd helloworld
Create a file named app.py and paste the following code into it:
import gradio as gr
def hello(name, intensity):
"""Return a friendly greeting."""
return "Hello " + name + "!" * int(intensity)
demo = gr.Interface(
fn=hello,
inputs=["text", "slider"],
outputs=["text"],
title="Hello World 👋🌎",
description=("Type your name below and hit 'Submit', and try the slider to "
"make the greeting louder!"),
theme="soft",
flagging_mode="never",
)
demo.launch()
This code creates a web service that responds to HTTP GET requests.
Create a file named requirements.txt and paste the following code into it:
gradio~=5.0
This code adds the Gradio package needed by the sample.
Your app is finished and ready to be deployed.
Deploy from source automatically builds a container image from source code and deploys it.
To deploy from source:
In your source code directory, deploy the current folder using the following command:
gcloud run deploy --source .
When you are prompted for the service name, press Enter to accept the
default name, for example helloworld.
If you are prompted to enable additional APIs on the project,
for example, the Artifact Registry API, respond by pressing
y.
When you are prompted for region: select the region
of your choice, for example europe-west1.
If you are prompted to create a repository in the specified region, respond by pressing y.
If you are prompted to allow public access:
respond y. You might not see this prompt if there is a domain
restriction organization policy that prevents it; for more details see the
Before you begin section.
Then wait a few moments until the deployment is complete. On success, the command line displays the service URL.
Visit your deployed service by opening the service URL in a web browser.
Cloud Run is regional, which means the infrastructure that
runs your Cloud Run services is located in a specific region and is
managed by Google to be redundantly available across
all the zones within that region.
Meeting your latency, availability, or durability requirements are primary
factors for selecting the region where your Cloud Run services are run.
You can generally select the region nearest to your users but you should consider
the location of the other Google Cloud
products that are used by your Cloud Run service.
Using Google Cloud products together across multiple locations can affect
your service's latency as well as cost.
Cloud Run is available in the following regions:
asia-east1 (Taiwan)
asia-northeast1 (Tokyo)
asia-northeast2 (Osaka)
asia-south1 (Mumbai, India)
asia-southeast3 (Bangkok)
europe-north1 (Finland)
europe-north2 (Stockholm)
europe-southwest1 (Madrid)
europe-west1 (Belgium)
europe-west4 (Netherlands)
europe-west8 (Milan)
europe-west9 (Paris)
me-west1 (Tel Aviv)
northamerica-south1 (Mexico)
us-central1 (Iowa)
us-east1 (South Carolina)
us-east4 (Northern Virginia)
us-east5 (Columbus)
us-south1 (Dallas)
us-west1 (Oregon)
africa-south1 (Johannesburg)
asia-east2 (Hong Kong)
asia-northeast3 (Seoul, South Korea)
asia-southeast1 (Singapore)
asia-southeast2 (Jakarta)
asia-south2 (Delhi, India)
australia-southeast1 (Sydney)
australia-southeast2 (Melbourne)
europe-central2 (Warsaw, Poland)
europe-west10 (Berlin)
europe-west12 (Turin)
europe-west2 (London, UK)
europe-west3 (Frankfurt, Germany)
europe-west6 (Zurich, Switzerland)
me-central1 (Doha)
me-central2 (Dammam)
northamerica-northeast1 (Montreal)
northamerica-northeast2 (Toronto)
southamerica-east1 (Sao Paulo, Brazil)
southamerica-west1 (Santiago, Chile)
us-west2 (Los Angeles)
us-west3 (Salt Lake City)
us-west4 (Las Vegas)
If you already created a Cloud Run service, you can view the region in the Cloud Run dashboard in the Google Cloud console.
To avoid additional charges to your Google Cloud account, delete all the resources you deployed with this quickstart.
Cloud Run doesn't charge you when your deployed service isn't in use. However, you might still be charged for storing the container image in Artifact Registry. To delete Artifact Registry repositories, follow the steps in Delete repositories in the Artifact Registry documentation.
Cloud Run services don't incur costs until they receive requests. To delete your Cloud Run service, follow one of these steps:
To delete a service:
In the Google Cloud console, go to the Cloud Run Services page:
Locate the service you want to delete in the services list, and click its checkbox to select it.
Click Delete. This deletes all revisions of the service.
To delete a service, run the following command:
gcloud run services delete SERVICE --region REGION
Replace the following:
Deleting your Google Cloud project stops billing for all resources in that project. To release all Google Cloud resources in your project, follow these steps:
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
For more information on building a container from code source and pushing to a repository, see:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-09 UTC.