Deploying to Cloud Run using Cloud Build Stay organized with collections Save and categorize content based on your preferences.
Cloud Run lets you run stateless images in aserverless environment.Using Cloud Build, you can deploy images from Artifact Registry toCloud Run. You can deploy an existing image, build and deploy an image,or automate the deployment.
Note: You can also use Cloud Deploy to set up a continuous-deliverypipeline to deploy to Cloud Run.Learn more.Before you begin
Enable the Cloud Build, Cloud Run, Artifact Registry, and Resource Manager APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission.Learn how to grant roles.
Have your application source code ready. Your source code needs to be storedin a repository such as GitHub or Bitbucket.
To run the
gcloudcommands in this page, installtheGoogle Cloud CLI.If you're using VPC Service Controls, thenset up a private pool in theVPC Service Controls perimeter. You must alsoconfigureCloud Run for VPC Service Controls.
Required Identity and Access Management permissions
In the Google Cloud console, go to thesettings Cloud BuildPermissions page:
For yourspecified Cloud Build service accountordefault Cloud Build service account, set the status of the following roles toEnabled:
- Cloud Run Admin (
roles/run.admin) | Lets Cloud Build deploy new services to Cloud Run.- In the Assign Service Account User Role panel,choose a service account to impersonate and then clickGrant Permission.
- Storage Admin (
roles/storage.admin) | Enables reading and writing from Cloud Storage. - Artifact Registry Writer (
roles/artifactregistry.writer) | Allows pulling images from and writing to Artifact Registry. - Logs Writer (
roles/logging.logWriter) | Allows log entries to be written to Cloud Logging. - Cloud Build Editor (
roles/cloudbuild.builds.editor) | Allows your service account to run builds.
- Cloud Run Admin (
Building and deploying an image
Cloud Build lets you build an image, store the built imagein Artifact Registry, and then deploy the image to Cloud Run.
To build and deploy an image:
In your project root directory, create a config file named
cloudbuild.yaml.In the build config file, add
dockerbuild steps to build the image andpush it to Artifact Registry, and then add agcloudbuild step toinvoke thegcloud run deploycommand to deploy the image onCloud Run:steps:# Build the image-name:'gcr.io/cloud-builders/docker'args:['build','-t','LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE','.']# Push the image to Artifact Registry-name:'gcr.io/cloud-builders/docker'args:['push','LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE']# Deploy image to Cloud Run-name:'gcr.io/google.com/cloudsdktool/cloud-sdk'entrypoint:gcloudargs:['run','deploy','SERVICE_NAME','--image','LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE','--region','SERVICE_REGION']images:-'LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE'Where:
REPOSITORYis the name of the Artifact Registryrepository from where you deploy your image.LOCATIONis the location of yourArtifact Registry repository, such asus-east1.PROJECT_IDis your Google Cloudproject ID where your image is stored.SERVICE_NAMEis the name of theCloud Run service.SERVICE_REGIONis theregion of the Cloud Run service you are deploying.IMAGEis the name of your image inArtifact Registry.
Navigate to your project root directory and run the following command, where
LOCATIONis one of thesupported build regions to run the build:gcloudbuildssubmit--region=LOCATION
After successful completion, a success message is displayed along with the URLof the deployed service.
Continuous deployment
You can automate the deployment of your software to Cloud Run bycreating Cloud Build triggers. You canconfigure your triggers to build and deploy images whenever you update yoursource code.
To automate your deployment:
In your repository root, add a config file named
cloudbuild.yamlwith stepsto build the image, push the image to Artifact Registry, and theninvoke thegcloud run deploycommand:steps:# Build the image-name:'gcr.io/cloud-builders/docker'args:['build','-t','LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE/SERVICE_NAME:$COMMIT_SHA','.']# Push the image to Artifact Registry-name:'gcr.io/cloud-builders/docker'args:['push','LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE/SERVICE_NAME:$COMMIT_SHA']# Deploy image to Cloud Run-name:'gcr.io/google.com/cloudsdktool/cloud-sdk'entrypoint:gcloudargs:-'run'-'deploy'-'SERVICE_NAME'-'--image'-'LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE/SERVICE_NAME:$COMMIT_SHA'-'--region'-'SERVICE_REGION'images:-'LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE/SERVICE_NAME:$COMMIT_SHA'Where:
REPOSITORYis the name of the Artifact Registryrepository from where you deploy your image.LOCATIONis the location of yourArtifact Registry repository, such asus-east1.PROJECT_IDis your Google Cloudproject ID where your image is stored.SERVICE_NAMEis the name of theCloud Run service.SERVICE_REGIONis theregion of the Cloud Run service you are deploying.IMAGEis the name of your image inArtifact Registry.
The
$COMMIT_SHAsubstitution variable is populated byCloud Build when triggered from a Git repository.Create a build trigger with the config file created in the previous step:
Open theTriggers page:
ClickCreate Trigger.
In theName field, enter a name for your trigger.
UnderRegion, select theregion for your trigger.
Note: The region for your trigger must match the regionof the Cloud Run service you're deploying to.UnderEvent, select the repository event to start your trigger.
UnderSource, select your repository and the branch or tag namethat will start your trigger.For more information on specifying which branches to autobuild, seeCreating a build trigger.
UnderConfiguration, selectCloud Buildconfiguration file (YAML or JSON).
In theCloud Build configuration file location field,type
cloudbuild.yamlafter the/.ClickCreate to save your build trigger.
Now, when you push new code to your repository, Cloud Buildinvokes a build and deploys the service to Cloud Run.
For more information on creating Cloud Build triggers, seeCreating and managing build triggers.
Code examples
Here are some sample repositories, each of which contains a sampleapplication and a build config file to deploy application to Cloud Run:
- deploy-prebuilt:A code example that shows how to deploy a prebuilt image to Cloud Run.
- run-example-builddeploy: A code example that shows how to build and deploy an image to Cloud Run.
What's next
- Learn how touse Cloud Deploy to deploy to Cloud Run.
- Learn how todeploy on GKE.
- Learn how todeploy on Cloud Run functions.
- Learn how todeploy on App Engine.
- Learn how todeploy on Firebase.
- Learn how toperform blue-green deployments on Compute Engine.
- Learn how totroubleshoot build errors.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.