Knative serving에서는 컨테이너 계약을 준수하는 한 컨테이너 이미지를 빌드할 수 있는 모든 도구로 빌드된 컨테이너 이미지를 사용할 수 있습니다.
특히 코드가 PORT 환경 변수로 정의된 포트로 HTTP 요청을 리슨해야 합니다. 이 PORT 환경 변수는 Knative serving에서 사용자의 컨테이너로 자동으로 주입됩니다.
이 페이지에서는 컨테이너 이미지를 빌드하는 몇 가지 방법을 설명합니다.
Dockerfile 사용
Buildpack 사용
Dockerfile을 사용하여 빌드
Dockerfile을 사용하는 경우 다음 방법 중 하나를 사용하여 빌드할 수 있습니다.
Cloud Build를 사용하여 빌드
Docker를 사용하여 로컬에서 빌드
Cloud Build를 사용하여 빌드
Google Cloud에서 이미지를 빌드하려면 다음 단계를 따르세요.
소스 및 Dockerfile이 포함된 폴더로 이동합니다.
다음 명령어를 실행합니다.
gcloudbuildssubmit--tagIMAGE_URL
IMAGE_URL을 컨테이너 이미지에 대한 참조(예: gcr.io/cloudrun/hello)로 바꿉니다.
Buildpack에 대한 자세한 내용은 Buildpack 웹사이트를 참조하세요.
Google은 Knative serving을 포함하여 Google Cloud 컨테이너 플랫폼에서 실행되도록 설계된 컨테이너 이미지로 소스 코드를 빌드하는 CNCF 호환 Buildpack 집합을 제공합니다.
현재 지원되는 플랫폼은 다음과 같습니다.
Go
Node.js
Python
Java
.NET Core
Cloud Build를 사용하여 Buildpack으로 빌드
Buildpack으로 빌드하려면 다음 안내를 따르세요.
소스가 포함된 폴더로 이동합니다.
다음 명령어를 실행합니다.
gcloud builds submit --pack image=IMAGE_URL
IMAGE_URL을 컨테이너 이미지 URL(예: gcr.io/myproject/myservice)로 바꿉니다.
[[["이해하기 쉬움","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-09-04(UTC)"],[],[],null,["# Building containers\n\nKnative serving accepts container images built with any tool capable of\nbuilding container images, as long as they respect the [container contract](/kubernetes-engine/enterprise/knative-serving/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 Knative serving into your container.\n\nThis page describes several ways to build container images:\n\n- Using a Dockerfile\n- Using Buildpacks\n\nBuilding using a Dockerfile\n---------------------------\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### Building using Cloud Build\n\nTo build your image on Google Cloud:\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, `gcr.io/cloudrun/hello`.\n\nFor detailed Cloud Build instructions, see\n[Deploying to Knative serving](/build/docs/deploying-builds/deploy-cloud-run#building_and_deploying_a_container).\n\nFor tips on improving build performance, see\n[Speeding up your Builds](/build/docs/speeding-up-builds)\n\n### Building locally and pushing 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 Buildpacks.\n\nBefore building your sources into a container image (\"containerizing\") using\nDocker, you need a\n[Dockerfile](https://docs.docker.com/engine/reference/builder/) to be present\nalong your sources. The following instructions use Container Registry as the\nimage registry.\n| **Caution:** Container Registry is deprecated. Effective March 18, 2025,\n| Container Registry is shut down, and writing images to Container Registry is unavailable. For\n| details on the deprecation and how to migrate to Artifact Registry, see\n| [Container Registry deprecation](/container-registry/docs/deprecations/container-registry-deprecation).\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, `gcr.io/cloudrun/hello`.\n3. If you have not yet configured Docker to use the Google Cloud CLI to\n authenticate requests to Container Registry, do so now using the command:\n\n ```bash\n gcloud auth configure-docker\n ```\n\n You need to do this before you can push or pull images using Docker. You\n only need to do it once.\n4. Push the container image to 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, `gcr.io/cloudrun/hello`.\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\nBuilding using Buildpacks\n-------------------------\n\nFor complete information on Buildpacks, see the\n[Buildpacks](https://buildpacks.io/) website.\nGoogle provides a set of\n[CNCF-compatible Buildpacks](/docs/buildpacks/overview)\nthat build source code into container images designed to run\non Google Cloud container platforms, including Knative serving.\n\nThese platforms are currently supported:\n\n- Go\n- Node.js\n- Python\n- Java\n- .NET Core\n\n### Building with Buildpacks using Cloud Build\n\nTo build with a Buildpack:\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 the container image URL, for example,\n `gcr.io/myproject/myservice`.\n3. Wait for the build to complete.\n\n### Building with Buildpack using the `pack` command line\n\nTo build using the [pack command](https://github.com/buildpacks/pack):\n\n1. If you haven't already done so, [install Docker](https://docs.docker.com/install/).\n\n2. If you have not yet configured Docker to use the Google Cloud CLI to\n authenticate requests to Container Registry, do so now using the command:\n\n ```bash\n gcloud auth configure-docker\n ```\n\n You need to do this before you can push or pull images using Docker. You\n only need to do it once.\n3. If you haven't already done so, [install `pack`](https://buildpacks.io/docs/tools/pack/cli/install/).\n\n4. Navigate to the folder containing your sources.\n\n5. Run the following command to build and push to your 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, `gcr.io/cloudrun/hello`.\n6. 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 learn more about the contract your containers must respect to be deployed\n to Knative serving, see\n [Container Contract](/kubernetes-engine/enterprise/knative-serving/docs/reference/container-contract).\n\n- To deploy your built containers to Knative serving, follow\n [Deploying Services](/kubernetes-engine/enterprise/knative-serving/docs/deploying).\n\n- To automate the builds and deployments of your Knative serving\n services using Cloud Build Triggers,\n [set up Continuous Deployment](/kubernetes-engine/enterprise/knative-serving/docs/continuous-deployment-with-cloud-build)."]]