Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Les compilateurs sont des images avec versions gérées qui contiennent tous les composants nécessaires à la création d'un conteneur exécutable. Chaque compilateur utilise une distribution de système d'exploitation spécifique comme image de base, comme Ubuntu 22, et accepte plusieurs versions de langages de programmation.
Vous devrez peut-être personnaliser la version du compilateur si vous avez besoin :
D'une dépendance spécifique à l'OS disponible uniquement dans une version de compilateur spécifique.
D'une version spécifique du langage de programmation qui n'est disponible que dans une version de compilateur spécifique.
Builds locaux
Pour les builds locaux, vous devez avoir installé la CLI Pack et Docker.
Avant de commencer
Installez Docker Community Edition (CE) sur votre poste de travail. Docker est utilisé par pack en tant que générateur d'images OCI.
Spécifier la version du compilateur à l'aide d'un descripteur project.toml
Vous pouvez utiliser un descripteur de projet de buildpacks (project.toml) pour définir le compilateur lors d'une compilation via la commande pack.
Dans le répertoire racine de votre application, créez un fichier nommé project.toml avec la configuration suivante :
[build]
builder = "BUILDER_IMAGE_URL"
Compilez votre application en exécutant la commande "pack" :
pack build SERVICE_IMAGE_NAME
Remplacez :
BUILDER_IMAGE_URL par l'URL du compilateur, par exemple gcr.io/buildpacks/builder:google-22 ;
SERVICE_IMAGE_NAME par le nom que vous avez choisi pour l'image de votre application.
Builds distants
Vous pouvez utiliser un compilateur spécifique avec Cloud Build en ajoutant l'option --pack lorsque vous envoyez votre projet.
Avant de commencer
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.
Initialisez un fichier project.toml à la racine du répertoire de votre application et collez-y la configuration suivante :
[build]
builder = "BUILDER_IMAGE_URL"
Déployez votre application à partir de la source :
gcloud run deploy --source . SERVICE_IMAGE_NAME
Remplacez :
BUILDER_IMAGE_URL par l'URL du compilateur, par exemple gcr.io/buildpacks/builder:google-22.
SERVICE_IMAGE_NAME par le nom de l'image de conteneur que vous avez créée.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eBuilders are versioned images containing necessary components to create a runnable container, using a specific OS distribution and supporting various programming language versions.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify a builder version using the \u003ccode\u003e--builder\u003c/code\u003e flag with the \u003ccode\u003epack\u003c/code\u003e command or through a \u003ccode\u003eproject.toml\u003c/code\u003e file for local builds.\u003c/p\u003e\n"],["\u003cp\u003eFor remote builds using Cloud Build, you can specify a builder by including the \u003ccode\u003e--pack\u003c/code\u003e flag in the \u003ccode\u003egcloud builds submit\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eWhen using Cloud Run to deploy from source, you can define the builder to be used by populating a \u003ccode\u003eproject.toml\u003c/code\u003e file with the specific builder URL.\u003c/p\u003e\n"],["\u003cp\u003eBoth local and remote builds require specific tools, such as the Pack CLI, Docker, Git, and gcloud CLI, installed and configured properly.\u003c/p\u003e\n"]]],[],null,["# Use a specific builder\n\n[Builders](/docs/buildpacks/builders) are versioned images that contain all the\ncomponents necessary to create a runnable container. Each builder uses a specific\nOS distribution as the base image, like Ubuntu 22, and supports multiple\nprogramming language versions.\n\nYou might need to customize the version of builder if you require:\n\n- A OS-specific dependency that is available only in a specific builder version.\n- A specific version of programing language that is available only in a specific builder version.\n\nLocal builds\n------------\n\nFor local builds, you must have the Pack CLI and Docker installed.\n\n### Before you begin\n\n1. Install [Docker Community Edition (CE)](https://docs.docker.com/engine/installation/) on your workstation. Docker is used by `pack` as an OCI image builder.\n2. Install [Pack CLI](https://buildpacks.io/docs/tools/pack/).\n3. Install the [Git source control](https://git-scm.com/downloads) tool to fetch the sample application from GitHub.\n\n### Specifying the builder version with `pack`\n\nYou can append the `--builder` flag to the pack command to specify the version\nof builder you want to use: \n\n```sh\npack build SERVICE_IMAGE_NAME --builder=BUILDER_IMAGE_URL\n```\n\nReplace:\n\n- `BUILDER_IMAGE_URL` with the URL of the builder. Example: `gcr.io/buildpacks/builder:google-22`\n- `SERVICE_IMAGE_NAME` with the name that you choose for your application image.\n\nTo learn more about the `pack` command, see the\n[CLI documentation](https://buildpacks.io/docs/tools/pack/cli/pack_build/)\n\n### Specifying the builder version with `project.toml`\n\nYou can use a buildpacks [project descriptor](https://buildpacks.io/docs/app-developer-guide/using-project-descriptor/)\n(`project.toml`) to set the builder when building with `pack`\n\n1. In your application root directory, create a file named `project.toml` with the following configuration: \n\n ```sh\n [build]\n builder = \"BUILDER_IMAGE_URL\"\n ```\n2. Build your application by running the \\`pack\\` command: \n\n ```sh\n pack build SERVICE_IMAGE_NAME\n ```\n\nReplace:\n\n- `BUILDER_IMAGE_URL` with the URL of the builder, for example, `gcr.io/buildpacks/builder:google-22`\n- `SERVICE_IMAGE_NAME` with the name that you choose for your application image.\n\nRemote builds\n-------------\n\nYou can use a specific builder with Cloud Build by appending the `--pack`\nflag when submitting your project.\n\n### Before you begin\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Build and Artifact Registry APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com, artifactregistry.googleapis.com&redirect=https://cloud.google.com/docs/buildpacks/build-application)\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Build and Artifact Registry APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com, artifactregistry.googleapis.com&redirect=https://cloud.google.com/docs/buildpacks/build-application)\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n\n| If you've already installed Google Cloud CLI previously, make sure you have the\n| latest available version by running `gcloud components update`.\n1. Ensure that your Google Cloud project has access to a container image repository. To configure access to a\n [Docker repository in\n Artifact Registry](/artifact-registry/docs/docker/store-docker-container-images):\n\n 1. Create a new Docker repository in the same location of your Google Cloud project. \n\n ```bash\n gcloud artifacts repositories create REPO_NAME \\\n --repository-format=docker \\\n --location=REGION --description=\"\u003cvar translate=\"no\"\u003eDESCRIPTION\u003c/var\u003e\"\n ```\n Replace:\n - `REPO_NAME` with the name that you choose for your Docker repository.\n - `REGION` with the [location](/artifact-registry/docs/repositories/repo-locations) in or nearest to the location of your Google Cloud project.\n - `DESCRIPTION` with a description of your choice.\n\n For example, to create a `docker` repository in\n `us-west2` with the description \"Docker repository\", you run: \n\n ```bash\n gcloud artifacts repositories create buildpacks-docker-repo --repository-format=docker \\\n --location=us-west2 --description=\"Docker repository\"\n ```\n 2. Verify that your repository was created: \n\n ```bash\n gcloud artifacts repositories list\n ```\n\n You should see name that you choose for your Docker repository in the list.\n\n### Build the application using a specific builder\n\n1. Use `gcloud` to submit the application source code to Cloud Build: \n\n ```sh\n gcloud builds submit --pack builder=BUILDER_IMAGE_URL,image=LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/SERVICE_IMAGE_NAME\n ```\n\n Replace:\n - `BUILDER_IMAGE_URL` with the url of the builder. Example: `gcr.io/buildpacks/builder:google-22`\n - `LOCATION` with the region name of your container repository. Example: **us-west2**`-docker.pkg.dev`\n - `PROJECT_ID` with the ID of your Google Cloud project.\n - `REPO_NAME` with the name of your Docker repository.\n - `SERVICE_IMAGE_NAME` with the name of your container image that you created.\n\n \u003cbr /\u003e\n\n To learn more about the `submit` command, see the\n [Cloud Build\n documentation](/sdk/gcloud/reference/builds/submit).\n2. Verify that the sample application was successfully published to \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e: \n\n ```bash\n gcloud artifacts docker images list LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME\n ```\n\n Replace:\n - `LOCATION` with the region name of your container repository. Example: **us-west2**`-docker.pkg.dev`\n - `PROJECT_ID` with the ID of your Google Cloud project.\n - `REPO_NAME` with the name of your Docker repository.\n\nDeploy from Source with Cloud Run\n---------------------------------\n\nYou can use a buildpacks [project descriptor](https://buildpacks.io/docs/app-developer-guide/using-project-descriptor/)\nfile e.g. `project.toml` to set the builder when [deploying from source with Cloud Run](/run/docs/deploying-source-code)\n\n1. Initialize a `project.toml` file at the root of your application directory and paste the following configuration into it: \n\n ```sh\n [build]\n builder = \"BUILDER_IMAGE_URL\"\n ```\n2. Deploy your application from source \n\n ```sh\n gcloud run deploy --source . SERVICE_IMAGE_NAME\n ```\n\nReplace:\n\n- `BUILDER_IMAGE_URL` with the URL of the builder. Example: `gcr.io/buildpacks/builder:google-22`\n- `SERVICE_IMAGE_NAME` with the name of your container image that you created."]]