Cloud Run 서비스의 경우 컨테이너 계약을 준수하는 한 컨테이너 이미지를 빌드할 수 있는 모든 도구로 빌드된 컨테이너 이미지를 사용할 수 있습니다.
특히 코드가 PORT 환경 변수로 정의된 포트로 HTTP 요청을 리슨해야 합니다. 이 PORT 환경 변수는 Cloud Run에서 사용자의 컨테이너로 자동으로 주입됩니다.
로컬에서 Docker를 사용하거나 Cloud Build를 사용하여 컨테이너 이미지에 소스를 빌드('컨테이너화')하기 전에 소스에 Dockerfile이 있어야 합니다.
Hello World 샘플에는 많이 사용되는 언어로 된 샘플 애플리케이션과 Dockerfile이 포함되어 있습니다.
Dockerfile을 사용하는 경우 다음 방법 중 하나를 사용하여 빌드할 수 있습니다.
Cloud Build를 사용하여 빌드
Docker를 사용하여 로컬에서 빌드
Cloud Build를 사용하여 빌드
Cloud Build를 사용하여 Google Cloud 에서 이미지를 빌드할 수 있습니다.
소스 및 Dockerfile이 포함된 폴더로 이동합니다.
다음 명령어를 실행합니다.
gcloudbuildssubmit--tagIMAGE_URL
IMAGE_URL을 컨테이너 이미지에 대한 참조(예: us-docker.pkg.dev/cloudrun/container/hello:latest)로 바꿉니다. Artifact Registry를 사용하는 경우 저장소REPO_NAME이 이미 생성되어 있어야 합니다. URL의 형식은 LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG입니다.
Docker가 로컬에 설치된 경우 Cloud Build 또는 Google Cloud 빌드팩을 사용하는 대신 docker build를 사용할 수 있습니다.
Docker를 사용하여 컨테이너 이미지를 빌드하려면 다음 안내를 따르세요.
소스 및 Dockerfile이 포함된 폴더로 이동합니다.
다음 명령어를 실행합니다.
dockerbuild.--tagIMAGE_URL
IMAGE_URL을 컨테이너 이미지에 대한 참조(예: us-docker.pkg.dev/cloudrun/container/hello:latest)로 바꿉니다. Artifact Registry를 사용하는 경우 저장소REPO_NAME이 이미 생성되어 있어야 합니다. URL의 형식은 LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG입니다.
Apple Silicon이 탑재된 Mac을 사용하는 경우 명령줄에서 --platform linux/amd64를 지정해야 합니다.
컨테이너 이미지를 지원되는 Container Registry로 푸시합니다.
dockerpushIMAGE_URL
IMAGE_URL을 컨테이너 이미지에 대한 참조(예: us-docker.pkg.dev/cloudrun/container/hello:latest)로 바꿉니다. Artifact Registry를 사용하는 경우 저장소REPO_NAME이 이미 생성되어 있어야 합니다. URL의 형식은 LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG입니다.
IMAGE_URL을 컨테이너 이미지에 대한 참조(예: us-docker.pkg.dev/cloudrun/container/hello:latest)로 바꿉니다. Artifact Registry를 사용하는 경우 저장소REPO_NAME이 이미 생성되어 있어야 합니다. URL의 형식은 LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG입니다.
IMAGE_URL을 컨테이너 이미지에 대한 참조(예: us-docker.pkg.dev/cloudrun/container/hello:latest)로 바꿉니다. Artifact Registry를 사용하는 경우 저장소REPO_NAME이 이미 생성되어 있어야 합니다. URL의 형식은 LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG입니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-24(UTC)"],[],[],null,["# Build sources to containers\n\nCloud Run supports [directly deploying source code](/run/docs/deploying-source-code),\nhowever, you can also build your source code into a container image and then\ndeploy this container image to Cloud Run. You can use container images\nfor any Cloud Run resource.\n\nCommon use cases for decoupling build and deploy operations:\n\n- **Continuous Integration and Delivery**: Developers author and push code to a source repository, a CI/CD system automatically builds this source code into a container, runs tests, and automatically deploys it to a staging environment.\n- **Infrastructure as Code**: Cloud Run resources that are managed using YAML or Terraform reference a container image URL. The source code written by developers need to be built into a container image.\n\nYou can use any system you want to build a container. This page describes\nthe following ways to use Cloud Build to build container images:\n\n- [Using a Dockerfile](#use-dockerfile)\n- [Using Google Cloud's buildpacks](#buildpacks)\n\nRequirements for Cloud Run services\n-----------------------------------\n\nFor Cloud Run services, you can use container images built with any tool capable of\nbuilding container images, as long as they respect the [container contract](/run/docs/reference/container-contract).\nIn particular, your code must listen for HTTP requests on the port defined by\nthe `PORT` environment variable. This `PORT` environment variable is\nautomatically injected by Cloud Run into your container.\n\nBefore you begin\n----------------\n\n- You need the [Google Cloud CLI](/run/docs/setup) to run some of the commands in this page.\n\n- Create a repository at a [supported container registry](/run/docs/deploying#images). To\n [create an Artifact Registry repository](/artifact-registry/docs/repositories/create-repos#create),\n run:\n\n gcloud artifacts repositories create \u003cvar translate=\"no\"\u003eREPOSITORY\u003c/var\u003e \\\n --repository-format=docker \\\n --location=\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --description=\"\u003cvar translate=\"no\"\u003eDESCRIPTION\u003c/var\u003e\" \\\n --immutable-tags \\\n --async\n\n- You can configure Docker to get access to Artifact Registry using the\n [gcloud CLI credential helper](/artifact-registry/docs/docker/authentication#gcloud-helper):\n\n ```bash\n gcloud auth configure-docker LOCATION-docker.pkg.dev\n ```\n Replace \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e with the region name of your container repository, for example, `us-west2`.\n\n \u003cbr /\u003e\n\nBuild using a Dockerfile\n------------------------\n\n| **Caution:** Don't include the file `~/.config/gcloud/gce` in your image. This file is generated if you run Google Cloud CLI commands as part of your image build. It can cause authentication issues when the image runs in Cloud Run.\n\nBefore building your sources into a container image (\"containerizing\") locally\nusing Docker or using Cloud Build, you need a\n[Dockerfile](https://docs.docker.com/engine/reference/builder/) to be present\nalong with your sources.\nThe [Hello World samples](https://github.com/GoogleCloudPlatform/cloud-run-samples/blob/main/README.md)\ncontain sample applications and Dockerfiles in many popular languages.\n\nIf you use Dockerfiles, you can use either of the following methods to build:\n\n- Build using Cloud Build\n- Build locally using Docker\n\n### Build using Cloud Build\n\nYou can build your image on Google Cloud by using [Cloud Build](/build/docs):\n\n1. Navigate to the folder containing your sources and Dockerfile.\n\n2. Run the command:\n\n ```bash\n gcloud builds submit --tag IMAGE_URL\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for\n example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry,\n the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must\n already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e\n .\n\nFor tips on improving build performance, see\n[Speeding up your builds](/build/docs/speeding-up-builds)\n\n### Build locally and push using Docker\n\nIf you have Docker [installed locally](https://docs.docker.com/install/), you\ncan use [`docker build`](https://docs.docker.com/engine/reference/commandline/build/)\ninstead of using Cloud Build or Google Cloud's buildpacks.\n\nTo build your container image using Docker:\n\n1. Navigate to the folder containing your sources and `Dockerfile`.\n\n2. Run the command:\n\n ```bash\n docker build . --tag IMAGE_URL\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for\n example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry,\n the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must\n already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e\n .\n\n Note that if you are using a Mac with Apple silicon, you must specify `--platform linux/amd64`\n in the command line.\n3. Push the container image to a supported container registry:\n\n ```bash\n docker push IMAGE_URL\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for\n example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry,\n the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must\n already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e\n .\n\nTo exclude local files from this process, follow the\n[`.dockerignore` configuration file](https://docs.docker.com/engine/reference/builder/#dockerignore-file)\ninstructions.\n\nBuild using Google Cloud's buildpacks\n-------------------------------------\n\n[Google Cloud's buildpacks](/docs/buildpacks/builders) is a set of\n[CNCF-compatible Buildpacks](https://buildpacks.io) that build source code into\ncontainer images designed to run on Google Cloud container platforms,\nincluding Cloud Run.\n\nFor a list of supported languages, refer to the [Google Cloud's buildpacks documentation](/docs/buildpacks/builders)\n\n### Build with Google Cloud's buildpacks using Cloud Build\n\nTo build with a Google Cloud's buildpacks:\n\n1. Navigate to the folder containing your sources.\n\n2. Run the command:\n\n ```\n gcloud builds submit --pack image=IMAGE_URL\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for\n example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry,\n the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must\n already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e\n .\n3. Wait for the build to complete.\n\n### Build with Google Cloud's buildpacks using the `pack` command line\n\nTo build using the [pack command](/docs/buildpacks/build-application):\n\n1. If you haven't already done so, [install Docker](https://docs.docker.com/install/).\n\n2. If you haven't already done so, [install `pack`](https://buildpacks.io/docs/tools/pack/cli/install/).\n\n3. Navigate to the folder containing your sources.\n\n4. Run the following command to build and push to your supported container registry:\n\n ```\n pack build --publish IMAGE_URL\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for\n example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry,\n the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must\n already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e\n .\n5. Wait for `pack` to finish.\n\nFor more information, read the instructions under\n[Building an Application](/docs/buildpacks/build-application).\n\nWhat's next\n-----------\n\n- To deploy your built containers to Cloud Run, follow [Deploying services](/run/docs/deploying).\n\n- Learn how to [create and update Cloud Run jobs](/run/docs/create-jobs)\n from your built container image.\n\n- After your container has been built, you can test locally before deploying to\n Cloud Run; see [Testing a Cloud Run service locally](/run/docs/testing/local) to learn more.\n\n- After you create or update a job using the built container, see how to\n [execute the job](/run/docs/execute/jobs) as a one-off, on a schedule, or as\n part of a [workflow](/run/docs/triggering/invoke-jobs-with-workflows).\n\n- To automate the builds and deployments of your Cloud Run services\n using Cloud Build Triggers, [set up continuous deployment](/run/docs/continuous-deployment).\n\n- To perform optimal container builds for Java application, see\n [Building Java containers with Jib](/java/getting-started/jib)."]]