Créer des images de conteneurs multi-architectures pour Dataflow
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Si vous utilisez un conteneur personnalisé dans Dataflow, celui-ci doit correspondre à l'architecture des VM de nœud de calcul. Ce document explique comment créer des conteneurs multi-architectures compatibles avec les VM x86 et basées sur l'architecture ARM.
Vous pouvez créer l'image de conteneur à l'aide de la CLI Docker ou de Cloud Build.
Utiliser Docker pour créer l'image
Créez un fichier Dockerfile. Utilisez l'instruction FROM pour spécifier une image de base multi-architecture.
FROM apache/beam_python3.10_sdk:2.50.0
# Make your customizations here, for example:
ENV FOO=/bar
COPY path/to/myfile ./
Installez l'outil Buildx. Pour vérifier si l'outil est installé, exécutez la commande suivante :
dockerbuildxversion
Exécutez la commande suivante pour créer une instance de compilateur qui utilise le pilote docker-container. Ce pilote est requis pour créer des images multi-architectures.
dockerbuildxcreate--driver=docker-container--use
L'option --use définit la nouvelle instance de compilateur en tant que compilateur actuel.
Exécutez la commande suivante pour configurer Docker afin d'authentifier les requêtes envoyées à Artifact Registry.
gcloudauthconfigure-dockerREGION-docker.pkg.dev
Remplacez REGION par la région du dépôt Artifact Registry.
Exécutez la commande suivante pour créer et transférer l'image de conteneur dans Artifact Registry :
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\u003eThis document provides instructions on creating multi-architecture container images compatible with both x86 and Arm virtual machines (VMs) for use with Dataflow custom containers.\u003c/p\u003e\n"],["\u003cp\u003eYou can build these multi-architecture images using either the Docker CLI with Buildx or Google Cloud Build, and they should specify a multi-architecture base image within their Dockerfile.\u003c/p\u003e\n"],["\u003cp\u003eWhen using the Docker CLI, the \u003ccode\u003edocker buildx\u003c/code\u003e tool is necessary, employing the \u003ccode\u003edocker-container\u003c/code\u003e driver to build the multi-architecture images.\u003c/p\u003e\n"],["\u003cp\u003eCloud Build utilizes a \u003ccode\u003edocker_buildx.yaml\u003c/code\u003e configuration file to define the build process, which includes creating a builder instance and specifying the target platforms.\u003c/p\u003e\n"],["\u003cp\u003eTo verify that a container image is multi-architecture, check its manifest file in Artifact Registry for \u003ccode\u003earm64\u003c/code\u003e and \u003ccode\u003eamd64\u003c/code\u003e entries within the \u003ccode\u003eplatform\u003c/code\u003e section.\u003c/p\u003e\n"]]],[],null,["# Build multi-architecture container images for Dataflow\n\nIf you use a custom container in Dataflow, the container must\nmatch the architecture of the worker VMs. This document describes how to create\nmulti-architecture containers that are compatible with both x86 and Arm VMs.\n\nYou can use the Docker CLI or [Cloud Build](/build/docs/overview) to build\nthe container image.\n\nUse Docker to build the image\n-----------------------------\n\n1. Create a Dockerfile. Use the `FROM` instruction to specify a\n multi-architecture base image.\n\n FROM apache/beam_python3.10_sdk:2.50.0\n\n # Make your customizations here, for example:\n ENV FOO=/bar\n COPY path/to/myfile ./\n\n2. Install the\n [Buildx](https://docs.docker.com/build/architecture/)\n tool. To check whether the tool is installed, run the following command:\n\n docker buildx version\n\n3. Run the following command to create a builder instance that uses the\n `docker-container` driver. This driver is required to build\n multi-architecture images.\n\n docker buildx create --driver=docker-container --use\n\n The `--use` flag sets the new builder instance as the current builder.\n4. Run the following command to configure Docker to authenticate requests to Artifact Registry.\n\n gcloud auth configure-docker \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e-docker.pkg.dev\n\n Replace \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the region of the Artifact Registry repository.\n5. Run the following command to build and push the container image to\n Artifact Registry:\n\n docker buildx build \\\n --platform=linux/amd64,linux/arm64 \\\n -t \u003cvar translate=\"no\"\u003eREGISTRY\u003c/var\u003e/\u003cvar translate=\"no\"\u003eIMAGE\u003c/var\u003e:\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e \\\n --push .\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eREGISTRY\u003c/var\u003e: the Docker repository\n - \u003cvar translate=\"no\"\u003eIMAGE\u003c/var\u003e: the image name\n - \u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e: the image tag\n\nUse Cloud Build to build the image\n----------------------------------\n\n1. Create a Dockerfile. Use the `FROM` instruction to specify a\n multi-architecture base image.\n\n FROM apache/beam_python3.10_sdk:2.50.0\n\n # Make your customizations here, for example:\n ENV FOO=/bar\n COPY path/to/myfile ./\n\n2. In the same directory that contains the Dockerfile, create a file named\n `docker_buildx.yaml`. Paste in the following text:\n\n steps:\n - name: 'docker'\n args: ['buildx', 'create', '--driver', 'docker-container', '--name', 'container', '--use']\n - name: 'docker'\n args: ['buildx', 'build', '--platform', 'linux/amd64,linux/arm64', '-t', '\u003cvar translate=\"no\"\u003eREGISTRY\u003c/var\u003e/\u003cvar translate=\"no\"\u003eIMAGE\u003c/var\u003e:\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e', '--push', '.']\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eREGISTRY\u003c/var\u003e: the Docker repository\n - \u003cvar translate=\"no\"\u003eIMAGE\u003c/var\u003e: the image name\n - \u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e: the image tag\n3. To build and push the image, run the\n [`gcloud builds submit` command](/sdk/gcloud/reference/builds/submit):\n\n gcloud builds submit --region=\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e --config docker_buildx.yaml\n\n Replace \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the region of the Cloud Build\n service to use.\n\nFor more information, see\n[Build and push a Docker image with Cloud Build](/build/docs/build-push-docker-image).\n\nVerify the container image\n--------------------------\n\n1. Open the **Repositories** page in the Google Cloud console.\n\n [Open the Repositories page](https://console.cloud.google.com/artifacts)\n2. Click the repository with the container image.\n\n3. Click the image to see its versions.\n\n4. Click a version.\n\n5. Click **Manifest**.\n\n6. In the manifest file, the `platform` section should have entries for\n `arm64` and `amd64`. For example:\n\n {\n \"schemaVersion\": 2,\n \"mediaType\": \"application/vnd.docker.distribution.manifest.list.v2+json\",\n \"manifests\": [\n {\n \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n \"digest\": \"sha256:441d5438885049e2b388523a8cb5b77ea829c3c3f53326fb221fe185abd67f07\",\n \"size\": 3074,\n \"platform\": {\n \"architecture\": \"amd64\",\n \"os\": \"linux\"\n }\n },\n {\n \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n \"digest\": \"sha256:d3b98b0f8f3f555f5453c79b240bd2b862d4f52d853fe81bae55f01a663de29c\",\n \"size\": 3073,\n \"platform\": {\n \"architecture\": \"arm64\",\n \"os\": \"linux\"\n }\n }\n ]\n }\n\nWhat's next\n-----------\n\n- [Use Arm VMs on Dataflow](/dataflow/docs/guides/use-arm-vms)\n- [Run a Dataflow job in a custom container](/dataflow/docs/guides/run-custom-container)"]]