Usar o streaming de imagem para reduzir o tempo de inicialização do contêiner
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Neste documento, descrevemos como usar o streaming de imagens para extrair imagens de contêiner
em jobs de contêiner do Batch.
O streaming de imagens permite que os jobs do Batch sejam inicializados sem esperar
que o download de uma imagem de contêiner seja concluído, o que oferece os seguintes
benefícios:
Se as imagens de contêiner estiverem protegidas pelo VPC Service Controls,
atualize o perímetro de serviço
para incluir containerfilesystem.googleapis.com.
Limitações
O streaming de imagens em lote tem as seguintes limitações:
O Batch só é compatível com o streaming de imagens para imagens de contêiner
armazenadas no Artifact Registry. Se você usa o Container Registry para gerenciar
suas imagens de contêiner, faça a transição para o Artifact Registry.
Execute as VMs do job do Batch no mesmo local em que você armazena a imagem do contêiner no Artifact Registry.
Contêineres que usam o manifesto de imagem do Docker versão 2, esquema 1, não são compatíveis.
Ao usar o streaming de imagem, os executáveis de contêineres só são compatíveis com os seguintes campos:
imageUri
commands
entrypoint
volumes
enableImageStreaming
Imagens de contêiner com camadas vazias ou duplicadas não são aceitas.
Criar um job que use o streaming de imagens
Crie um job de contêiner do Batch que use o streaming de imagens fazendo
o seguinte:
Use a Google Cloud CLI ou a API REST para
criar um job de contêiner.
Para ativar o streaming de imagens em um contêiner executável, defina o campo
enableImageStreaming como true e o campo imageUri como uma imagem
armazenada em um
local do Artifact Registry
que contenha o local da VM do job.
"container":{..."enableImageStreaming":true}
Por exemplo, um job que usa o streaming de imagens teria um arquivo de configuração JSON semelhante a este:
LOCATION: o local regional ou multirregional do repositório em que a imagem está armazenada, por exemplo, us-east1 ou us. O
local do contêiner precisa ser o mesmo das VMs do
job em lote.
PROJECT-ID: o projeto que contém a imagem do contêiner. Se o ID do projeto contiver dois pontos (:), consulte
Projetos com escopo de domínio.
REPOSITORY: o nome do repositório em que a imagem
está armazenada.
IMAGE: o nome da imagem do contêiner.
TAG: a tag aplicada à imagem.
A seguir
Se você tiver problemas para criar ou executar um job, consulte Solução de problemas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-02 UTC."],[[["\u003cp\u003eImage streaming reduces latency and speeds up job execution by allowing Batch jobs to start without waiting for full container image downloads.\u003c/p\u003e\n"],["\u003cp\u003eImage streaming is only supported for container images stored in Artifact Registry, and the job's VMs must be in the same location as the image.\u003c/p\u003e\n"],["\u003cp\u003eTo enable image streaming, set the \u003ccode\u003eenableImageStreaming\u003c/code\u003e field to \u003ccode\u003etrue\u003c/code\u003e in the container runnable configuration and specify the Artifact Registry image URI.\u003c/p\u003e\n"],["\u003cp\u003eWhen using Image streaming, container runnables support only specific fields: \u003ccode\u003eimageUri\u003c/code\u003e, \u003ccode\u003ecommands\u003c/code\u003e, \u003ccode\u003eentrypoint\u003c/code\u003e, \u003ccode\u003evolumes\u003c/code\u003e, and \u003ccode\u003eenableImageStreaming\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe container image used for image streaming must not have any empty or duplicate layers and must be of docker manifest version 2, schema 2.\u003c/p\u003e\n"]]],[],null,["# Use Image streaming to reduce container startup time\n\nThis document describes how to use Image streaming to pull container images\ninto Batch container jobs.\n\nImage streaming enables Batch jobs to initialize without waiting\nfor a container image to finish downloading, which provides the following\nbenefits:\n\n- Reduced latency when pulling large images\n- Faster time to begin job execution\n\nBefore you begin\n----------------\n\n1. If you haven't used Batch before, review [Get started with Batch](/batch/docs/get-started) and enable Batch by completing the [prerequisites for projects and users](/batch/docs/get-started#prerequisites).\n2.\n\n To get the permissions that\n you need to create a job,\n\n ask your administrator to grant you the\n following IAM roles:\n\n - [Batch Job Editor](/iam/docs/roles-permissions/batch#batch.jobsEditor) (`roles/batch.jobsEditor`) on the project\n - [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the [job's service account](/batch/docs/create-run-job-custom-service-account#create-job-service-account), which by default is the [default Compute Engine service account](/compute/docs/access/service-accounts#default_service_account)\n\n\n For more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\n You might also be able to get\n the required permissions through [custom\n roles](/iam/docs/creating-custom-roles) or other [predefined\n roles](/iam/docs/roles-overview#predefined).\n3. If you haven't already done so, enable the Container File System API by\n running the following command:\n\n ```\n gcloud services enable containerfilesystem.googleapis.com\n ```\n4. If your container images are protected by VPC Service Controls, [update your service perimeter](/vpc-service-controls/docs/manage-service-perimeters#update) to include `containerfilesystem.googleapis.com`.\n\n\u003cbr /\u003e\n\nLimitations\n-----------\n\nBatch Image streaming has the following limitations:\n\n- Batch only supports Image streaming for container images that are stored in Artifact Registry. If you currently use Container Registry to manage your container images, you can [transition to Artifact Registry](/artifact-registry/docs/transition/transition-from-gcr).\n- You must run your Batch job's VMs in the same [location](/artifact-registry/docs/repositories/repo-locations) as where you store your container image in Artifact Registry.\n- Containers that use the Docker image manifest version 2, schema 1 aren't supported.\n- When you use Image streaming, [containers runnables](/batch/docs/reference/rest/v1/projects.locations.jobs#container) only support the following fields:\n - `imageUri`\n - `commands`\n - `entrypoint`\n - `volumes`\n - `enableImageStreaming`\n- Container images with empty layers or duplicate layers aren't supported.\n\nCreate a job that uses Image streaming\n--------------------------------------\n\nCreate a Batch container job that uses Image streaming by doing\nthe following:\n\nUse the Google Cloud CLI or REST API to\n[create a container job](/batch/docs/create-run-basic-job#create-basic-container-job).\nTo enable Image streaming for a container runnable, set\n`enableImageStreaming` field to `true` and set the `imageUri` field to an image\nthat is stored in an\n[Artifact Registry location](/artifact-registry/docs/repositories/repo-locations)\nthat contains the location of the job's VM. \n\n \"container\": {\n ...\n \"enableImageStreaming\": true\n }\n\n| **Note:** When you use Image streaming, [containers runnables](/batch/docs/reference/rest/v1/projects.locations.jobs#container) only support the `imageUri`, `commands`, `entrypoint`, `volumes`, and `enableImageStreaming` fields.\n\nFor example, a job that uses Image streaming would have a JSON\nconfiguration file similar to the following: \n\n {\n \"taskGroups\": [\n {\n \"taskCount\": \"1\",\n \"taskCountPerNode\": \"1\",\n \"taskSpec\": {\n \"runnables\": [\n {\n \"container\": {\n \"imageUri\": \"\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e-docker.pkg.dev/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/\u003cvar translate=\"no\"\u003eREPOSITORY\u003c/var\u003e/\u003cvar translate=\"no\"\u003eIMAGE\u003c/var\u003e:\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e\",\n \"enableImageStreaming\": true\n }\n }\n ]\n }\n }\n ],\n \"allocationPolicy\": {\n \"instances\": [\n {\n \"policy\": {\n \"machineType\": \"e2-standard-4\"\n }\n }\n ]\n },\n \"logsPolicy\": {\n \"destination\": \"CLOUD_LOGGING\"\n }\n }\n\nReplace the following values:\n\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the regional or multi-regional [location](/artifact-registry/docs/repositories/repo-locations) of the repository where the image is stored, for example `us-east1` or `us`. The location of the container must be the same as the location of the Batch job's VMs.\n- \u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e: the project that contains the container image. If your project ID contains a colon (`:`), see [Domain-scoped projects](/artifact-registry/docs/docker/names#domain).\n- \u003cvar translate=\"no\"\u003eREPOSITORY\u003c/var\u003e: the name of the repository where the image is stored.\n- \u003cvar translate=\"no\"\u003eIMAGE\u003c/var\u003e: the name of the container image.\n- \u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e: the tag applied to the image.\n\nWhat's next\n-----------\n\n- If you have issues creating or running a job, see [Troubleshooting](/batch/docs/troubleshooting).\n- [View jobs and tasks](/batch/docs/view-jobs-tasks).\n- Learn about more [job creation options](/batch/docs/create-run-job#job-creation-options)."]]