This page describes how to configure the entrypoint command and arguments for a Cloud Run job.
When Cloud Run starts a container, it runs the image's default
entrypoint command and default command arguments. If you want to
override the image's default entrypoint and command arguments, you can use the
command
and args
fields in the container configuration. The command
field
specifies the actual command run by the container. The args
field specifies
the arguments passed to that command.
Note that you can have a maximum of 1000 arguments per container for each job.
This page shows you how to configure the command, arguments, and start order for containers in your Cloud Run jobs. You can configure these settings through the Google Cloud console, the Google Cloud CLI, or YAML.
Required roles
To get the permissions that you need to configure Cloud Run jobs, ask your administrator to grant you the following IAM roles:
-
Cloud Run Developer (
roles/run.developer
) on the Cloud Run job -
Service Account User (
roles/iam.serviceAccountUser
) on the service identity
For a list of IAM roles and permissions that are associated with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions. If your Cloud Run job interfaces with Google Cloud APIs, such as Cloud Client Libraries, see the service identity configuration guide. For more information about granting roles, see deployment permissions and manage access.
Configure entrypoint and arguments
To configure command entrypoint and arguments for jobs:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Click Deploy container and select Job to fill out the initial job settings page. If you are configuring an existing job, select the job, then click Edit.
Click Container, variables and secrets, connections, security to expand the job properties page.
Click the General tab.
- Specify the command you want the container to run, if not the command defined in your container, and optionally specify the arguments to the entrypoint command.
Click Create or Update.
gcloud
To set the start command and arguments for a new job:
gcloud run jobs create JOB_NAME --image IMAGE_URL --command COMMAND --args ARG1,ARG-N
Replace
- JOB_NAME with the name of your job.
- COMMAND with the command that the container is to start with if you are not using the default command.
- ARG1 with the argument you are sending to the container command. For more than one argument, use a comma-separated list.
- IMAGE_URL with a reference to the container image, for
example,
us-docker.pkg.dev/cloudrun/container/job:latest
.
To update command and args for an existing job:
gcloud run jobs update JOB_NAME --command COMMAND --args ARG1,ARG-N
YAML
If you are creating a new job, skip this step. If you are updating an existing job, download its YAML configuration:
gcloud run jobs describe JOB_NAME --format export > job.yaml
Update the
args:
andcommand
attributes:apiVersion: run.googleapis.com/v1 kind: Job metadata: name: JOB_NAME spec: template: spec: template: spec: containers: - args: - 'ARG1' - 'ARG-N' command: - COMMAND image: IMAGE
Replace
- COMMAND with the command that the container is to start with if you are not using the default command.
- ARG1 with the argument you are sending to the container command. Optionally specify additional arguments each in a separate line.
You can also specify more configuration such as environment variables or memory limits.
Update the existing job configuration:
gcloud run jobs replace job.yaml
To clear any entrypoint commands and arguments you have set (restore to container defaults), supply empty strings as follows:
gcloud run jobs update JOB_NAME --command "" --args ""
Use equals signs or commas in arguments
If you use equal signs in your arguments, supply these using the following format:
gcloud run deploy \
--args="--repo-allowlist=github.com/example/example_demo"
If your arguments use commas, refer to configuring environment variables for details on escaping those.
View container settings
To view the current container settings for your Cloud Run job:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Click the job you are interested in to open the Job details page.
Click the Configuration tab.
Locate the container setting in the configuration details.
gcloud
Use the following command:
gcloud run jobs describe JOB_NAME
Locate the container setting in the returned configuration.
Configure the container start order for sidecar deployments
To specify container start order in a sidecar deployment, you use the container dependencies feature. You specify any containers that have dependencies and list the containers they depend on. The containers that don't have any dependencies are always started first and concurrently.
You can use the Google Cloud console, the Google Cloud CLI, or YAML to specify the startup order:
Console
In the Google Cloud console, go to the Cloud Run page:
- For an existing job, click Jobs. Then click the job in the list and select View and edit job configuration to display the Edit Job form.
- For a new job, click Deploy container and select Job to display the Create job form.
For a new job, specify the job name, job container URL, region, number of tasks. In the Container(s), volumes, networking, security tab, do the following:
- Configure the main job container.
- To add each sidecar container you are deploying, click Add container.
- If a container depends on other containers, use the Container startup order menu to select the containers that Cloud Run must start before the current container.
For an existing job, follow these steps for each container:
- Examine the containers listed in the Container startup order menu.
- If a container depends on other containers, use the Container startup order menu to select the those containers.
Finish any other required configurations, then click Create for a new job or Update for an existing job. Wait for the deployment to finish.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
To deploy multiple containers to a job with a specified startup order, run the command:
gcloud beta run create JOB \ --container CONTAINER_1_NAME --image='JOB_IMAGE' \ --container CONTAINER_2_NAME --image='SIDECAR_IMAGE' --depends-on=CONTAINER_1_NAME \ --container CONTAINER_3_NAME --image='SIDECAR_IMAGE' --depends-on=CONTAINER_1_NAMECONTAINER_2_NAME
Replace:
- JOB with the name of the job you are deploying to. You can omit this parameter entirely, but you will be prompted for the job name if you omit it.
- CONTAINER_1_NAME with a name for the main job container.
- JOB_IMAGE with a reference to the main job container image, for example,
us-docker.pkg.dev/cloudrun/container/job:latest
. - CONTAINER_2_NAME with a name for the sidecar
container, for example
sidecar
. - SIDECAR_IMAGE with a reference to the sidecar container image.
If you want to configure each container in the deploy command, supply each container's configuration after the
container
parameters.
YAML
If you are creating a new job, skip this step. If you are updating an existing job, download its YAML configuration:
gcloud run jobs describe JOB_NAME --format export > job.yaml
Update the
container-dependencies
attribute:apiVersion: run.googleapis.com/v1 kind: Job metadata: annotations: run.googleapis.com/launch-stage: BETA name: JOB spec: template: metadata: annotations: run.googleapis.com/container-dependencies: '{"CONTAINER1":["CONTAINER2"], "CONTAINER3":["CONTAINER1","CONTAINER2"]}'
Replace
- CONTAINER1 with the name of the first container that depends on one or more container. Note that you can set the container name in the YAML: Cloud Run will automatically generate a name if one isn't specified.
- CONTAINER2 with the name of the container that must be started before CONTAINER1.
- CONTAINER3 with the name of the second container that depends on one or more containers.
In the example shown in the YAML snippet, CONTAINER2 is started first, CONTAINER1 is started second, and CONTAINER3 is started last.
Create or update the job using the following command:
gcloud run jobs replace job.yaml