Build sources to containers Stay organized with collections Save and categorize content based on your preferences.
Cloud Run supportsdirectly deploying source code,however, you can also build your source code into a container image and thendeploy this container image to Cloud Run. You can use container imagesfor any Cloud Run resource.
Common use cases for decoupling build and deploy operations:
- Continuous Integration and Delivery: Developers author and push codeto a source repository, a CI/CD system automatically builds this source code intoa container, runs tests, and automatically deploys it to a staging environment.
- Infrastructure as Code: Cloud Run resources that are managed usingYAML or Terraform reference a container image URL. The source code writtenby developers need to be built into a container image.
You can use any system you want to build a container. This page describesthe following ways to use Cloud Build to build container images:
Requirements for Cloud Run services
For Cloud Run services, you can use container images built with any tool capable ofbuilding container images, as long as they respect thecontainer contract.In particular, your code must listen for HTTP requests on the port defined bythePORT environment variable. ThisPORT environment variable isautomatically injected by Cloud Run into your container.
Before you begin
You need theGoogle Cloud CLI to run some of the commands in this page.
Create a repository at asupported container registry. Tocreate an Artifact Registry repository,run:
gcloudartifactsrepositoriescreateREPOSITORY\--repository-format=docker\--location=LOCATION\--description="DESCRIPTION"\--immutable-tags\--asyncYou can configure Docker to get access to Artifact Registry using thegcloud CLI credential helper:
Replacegcloudauthconfigure-dockerLOCATION-docker.pkg.dev
LOCATIONwith the region name of your container repository, for example,us-west2.
Build using a Dockerfile
Caution: Don't include the file~/.config/gcloud/gce in your image. This file isgenerated if you run Google Cloud CLI commands as part of your image build. It cancause authentication issues when the image runs in Cloud Run.Before building your sources into a container image ("containerizing") locallyusing Docker or using Cloud Build, you need aDockerfile to be presentalong with your sources.TheHello World samples contain sample applications and Dockerfiles in many popular languages.
If you use Dockerfiles, you can use either of the following methods to build:
- Build using Cloud Build
- Build locally using Docker
Build using Cloud Build
You can build your image on Google Cloud by usingCloud Build:
Navigate to the folder containing your sources and Dockerfile.
Run the command:
gcloudbuildssubmit--tagIMAGE_URL
ReplaceIMAGE_URL with a reference to the container image, forexample,
us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,therepositoryREPO_NAME mustalready be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.
For tips on improving build performance, seeSpeeding up your builds
Build locally and push using Docker
If you have Dockerinstalled locally, youcan usedocker buildinstead of using Cloud Build or Google Cloud's buildpacks.
To build your container image using Docker:
Navigate to the folder containing your sources and
Dockerfile.Run the command:
dockerbuild.--tagIMAGE_URL
ReplaceIMAGE_URL with a reference to the container image, forexample,
us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,therepositoryREPO_NAME mustalready be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.Note that if you are using a Mac with Apple silicon, you must specify
--platform linux/amd64in the command line.Push the container image to a supported container registry:
dockerpushIMAGE_URL
ReplaceIMAGE_URL with a reference to the container image, forexample,
us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,therepositoryREPO_NAME mustalready be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.
To exclude local files from this process, follow the.dockerignore configuration file instructions.
Build using Google Cloud's buildpacks
Google Cloud's buildpacks is a set ofCNCF-compatible Buildpacks that build source code intocontainer images designed to run on Google Cloud container platforms,including Cloud Run.
For a list of supported languages, refer to theGoogle Cloud's buildpacks documentation
Build with Google Cloud's buildpacks using Cloud Build
To build with a Google Cloud's buildpacks:
Navigate to the folder containing your sources.
Run the command:
gcloud builds submit --pack image=IMAGE_URL
ReplaceIMAGE_URL with a reference to the container image, forexample,
us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,therepositoryREPO_NAME mustalready be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.Wait for the build to complete.
Build with Google Cloud's buildpacks using thepack command line
To build using thepack command:
If you haven't already done so,install Docker.
If you haven't already done so,install
pack.Navigate to the folder containing your sources.
Run the following command to build and push to your supported container registry:
pack build --publishIMAGE_URL
ReplaceIMAGE_URL with a reference to the container image, forexample,
us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,therepositoryREPO_NAME mustalready be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.Wait for
packto finish.
For more information, read the instructions underBuilding an Application.
What's next
To deploy your built containers to Cloud Run, followDeploying services.
Learn how tocreate and update Cloud Run jobsfrom your built container image.
After your container has been built, you can test locally before deploying toCloud Run; seeTesting a Cloud Run service locally to learn more.
After you create or update a job using the built container, see how toexecute the job as a one-off, on a schedule, or aspart of aworkflow.
To automate the builds and deployments of your Cloud Run servicesusing Cloud Build Triggers,set up continuous deployment.
To perform optimal container builds for Java application, seeBuilding Java containers with Jib.
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.