Configure containers

This page describes how to configure the container port, entrypoint command and arguments for Cloud Run services, and how to configure entrypoint command and arguments for Cloud Run jobs.

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.

Configure the container port (services)

Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.

For Cloud Run services, Cloud Run injects the PORT environment variable into the container. The container should listen on the port defined by the PORT environment variable rather than a specific hardcoded port. However, if this is not possible, you can configure on which port requests are sent to the container. Note that port settings do not apply to Cloud Run jobs.

Console

  1. Go to Cloud Run

  2. Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.

  3. If you are configuring a new service, fill out the initial service settings page as desired, then click Next > Container, Variables & Secrets, Connections, Security to reach the service configuration page.

  4. Click the Container tab.

    image

  5. Specify the port you want requests to be sent to, if not the default value of `8080`. This also sets the `PORT` environment variable.

  6. Click Create or Deploy.

Command line

You can update a service's port configuration using the following command:

gcloud run services update SERVICE --port PORT

Replace

  • SERVICE with the name of the service.
  • PORT with the port to send requests to. Note that the default port is 8080.

You can also configure ports during deployment using the command:

gcloud run deploy --image IMAGE_URL --port PORT

Replace IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest.

YAML

You can download and view existing service configuration using the gcloud run services describe --format export command, which yields cleaned results in YAML format. You can then modify the fields described below and upload the modified YAML using the gcloud run services replace command. Make sure you only modify fields as documented.

  1. To view and download the configuration:

    gcloud run services describe SERVICE --format export > service.yaml
  2. Update the containerPort: attribute:

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: SERVICE
    spec:
      template:
        metadata:
          name: REVISION
        spec:
          containers:
          - image: IMAGE_URL
            ports:
            - containerPort: PORT
    

    Replace

    • SERVICE with the name of your Cloud Run service
    • IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest
    • PORT with the port to send requests to
    • REVISION with a new revision name or delete it (if present). If you supply a new revision name, it must meet the following criteria:
      • Starts with SERVICE-
      • Contains only lowercase letters, numbers and -
      • Does not end with a -
      • Does not exceed 63 characters
  3. Replace the service with its new configuration using the following command:

    gcloud run services replace service.yaml

Configure container entrypoint command and arguments

You can configure entrypoint commands and arguments for Cloud Run jobs and services.

For Cloud Run services

Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.

The specified container command and arguments override the default image ENTRYPOINT and CMD.

You can set entrypoint command and arguments using the console, the gcloud command line, or using a .yaml file when you create a new service or deploy a new revision:

Console

  1. Go to Cloud Run

  2. Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.

  3. If you are configuring a new service, fill out the initial service settings page as desired, then click Next > Container, Variables & Secrets, Connections, Security to reach the service configuration page.

  4. Click the Container tab.

    image

  5. 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.

  6. Click Create or Deploy.

Command line

You can update the start command and arguments of a given service by using the following command:

gcloud run services update SERVICE --command COMMAND --args ARG1,ARG-N

Replace

  • COMMAND with the command that the container is to start up with if you are not using the default command.
  • ARG1 with the argument you are sending to the container command, use a comma delimited list for more than one argument.

You can also specify entrypoint and arguments during deployment using the command:

gcloud run deploy --image IMAGE_URL --command COMMAND --args ARG1,ARG-N

Replace IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest

YAML

You can download and view existing service configuration using the gcloud run services describe --format export command, which yields cleaned results in YAML format. You can then modify the fields described below and upload the modified YAML using the gcloud run services replace command. Make sure you only modify fields as documented.

  1. To view and download the configuration:

    gcloud run services describe SERVICE --format export > service.yaml
  2. Update the command and args attributes:

    spec:
      containers:
      - image: IMAGE_URL
        command:
        - COMMAND
        args:
        - "ARG1"
        - "ARG-N"
    

    Replace

    • IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest
    • COMMAND with the command that the container is to start up with if you are not using the default command.
    • ARG1 with the argument you are sending to the container command, use a comma delimited list for more than one argument.
  3. Replace the service with its new configuration using the following command:

    gcloud run services replace service.yaml

For Cloud Run jobs

To configure command entrypoint and arguments for jobs:

Console

  1. Go to Cloud Run

  2. If you are configuring a new job, click the Jobs tab and fill out the initial job settings page as desired. If you are configuring an existing job, click the job, then click Edit.

  3. Click Container, Variables, Connections, Security to expand the job properties page.

  4. Click the General tab.

    image

  5. 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.

  6. Click Create or Update.

Command line

  1. To set the start command and arguments for a new job:

    gcloud beta 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 up with if you are not using the default command.
    • ARG1 with the argument you are sending to the container command, or use a comma delimited list for more than one argument.
    • Replace IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/job:latest.
  2. To update command and args for an existing job:

    gcloud beta run jobs update JOB_NAME --command COMMAND --args ARG1,ARG-N 

Using 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" \
  --args="--gh-webhook-secret=XX" \

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 service:

Console

  1. Go to Cloud Run

  2. Click the service you are interested in to open the Service details page.

  3. Click the Revisions tab.

  4. In the details panel at the right, the container setting is listed under the General tab.

Command line

  1. Use the following command:

    gcloud run services describe SERVICE
  2. Locate the container setting in the returned configuration.

To view the current container settings for your Cloud Run job:

Console

  1. Go to Cloud Run jobs

  2. Click the job you are interested in to open the Job details page.

  3. Click the Configuration tab.

  4. Locate the container setting in the configuration details.

Command line

  1. Use the following command:

    gcloud beta run jobs describe JOB_NAME
  2. Locate the container setting in the returned configuration.