Quickstart: Deploy to Cloud Run
This page shows you how to use Cloud Run to deploy a sample container.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project .
-
Make sure that you have the following role or roles on the project: Cloud Run Admin, Cloud Run Developer, Logs Viewer
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access .
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- In the Select a role list, select a role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save .
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project .
-
Make sure that you have the following role or roles on the project: Cloud Run Admin, Cloud Run Developer, Logs Viewer
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access .
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- In the Select a role list, select a role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save .
-
-
Make sure that you have the Service Account User role granted on the service identity. By default, the service identity is the Compute Engine default service account.
Grant the roles
To grant access on the service identity resource, use the
gcloud iam service-accounts add-iam-policy-binding
command, replacing the highlighted variables with the appropriate values:gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_EMAIL \ --member = " PRINCIPAL " \ --role = "roles/iam.serviceAccountUser"
Replace the following:
- SERVICE_ACCOUNT_EMAIL
: the service account email address
you are using as the service identity, such as:
- The Compute Engine default service account:
PROJECT_NUMBER -compute@developer.gserviceaccount.com
- A service account that you created:
SERVICE_ACCOUNT_NAME @ PROJECT_ID .iam.gserviceaccount.com
- The Compute Engine default service account:
- PRINCIPAL : the user identifier. This is typically the email address for a Google Account.
- SERVICE_ACCOUNT_EMAIL
: the service account email address
you are using as the service identity, such as:
- Review Cloud Run pricing or estimate costs with the pricing calculator .
Deploying the sample container
To deploy a container, follow these steps:
-
In the Google Cloud console, go to the Cloud Runpage:
-
Select Servicesfrom the menu, and click Deploy container.
-
In the Create serviceform, ensure the Deploy one revision from an existing container imageoption is selected.
-
In the Create servicepage, for Container image URL, click Test with a sample container.
-
In the Service namefield, enter a service name or use the default value.
-
In the Regionlist, use the default value
us-central1
, or select the region where you want to deploy your container. -
In the Authenticationsection, select Allow public access.
-
Click Create, and then wait for the container to deploy to Cloud Run. After deployment, the container's URL is displayed next to the text URL:.
-
To view the running container, click Copy to clipboardto copy its URL, and then paste the URL into your browser's address bar.
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 .
Cloud Run locations
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:
Subject to Tier 1 pricing
-
asia-east1
(Taiwan) -
asia-northeast1
(Tokyo) -
asia-northeast2
(Osaka) -
asia-south1
(Mumbai, India) -
europe-north1
(Finland)Low CO 2
-
europe-north2
(Stockholm)Low CO 2
-
europe-southwest1
(Madrid)Low CO 2
-
europe-west1
(Belgium)Low CO 2
-
europe-west4
(Netherlands)Low CO 2
-
europe-west8
(Milan) -
europe-west9
(Paris)Low CO 2
-
me-west1
(Tel Aviv) -
northamerica-south1
(Mexico) -
us-central1
(Iowa)Low CO 2
-
us-east1
(South Carolina) -
us-east4
(Northern Virginia) -
us-east5
(Columbus) -
us-south1
(Dallas)Low CO 2
-
us-west1
(Oregon)Low CO 2
Subject to Tier 2 pricing
-
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)Low CO 2
-
europe-west12
(Turin) -
europe-west2
(London, UK)Low CO 2
-
europe-west3
(Frankfurt, Germany) -
europe-west6
(Zurich, Switzerland)Low CO 2
-
me-central1
(Doha) -
me-central2
(Dammam) -
northamerica-northeast1
(Montreal)Low CO 2
-
northamerica-northeast2
(Toronto)Low CO 2
-
southamerica-east1
(Sao Paulo, Brazil)Low CO 2
-
southamerica-west1
(Santiago, Chile)Low CO 2
-
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 .
Cloud Run automatically scales your container instances based on demand, and you only pay for the CPU, memory, and networking consumed during request processing.
Clean up
To avoid additional charges to your Google Cloud account, delete all the resources you deployed with this quickstart.
Delete your repository
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.
Delete your service
Cloud Run services don't incur costs until they receive requests. To delete your Cloud Run service, follow one of these steps:
Console
To delete a service:
-
In the Google Cloud console, go to Cloud Run:
-
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.
gcloud
To delete a service, run the following command:
gcloud run services delete SERVICE --region REGION
Replace the following:
- SERVICE : name of your service.
- REGION : Google Cloud region of the service.
Delete your test project
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:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete .
- In the dialog, type the project ID, and then click Shut down to delete the project.
What's next
To learn how to build a container from code source, push to Artifact Registry, and deploy, see: