Configuring containers

This page describes how to configure the container port, entrypoint command and arguments.

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.

Configuring the container port

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

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 & DEPLOY NEW REVISION.

  3. Click SHOW ADVANCED SETTINGS > CONTAINER.

    image

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

  5. 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 gcr.io/PROJECT-ID/SERVICE --port PORT

Replace

  • PROJECT-ID with your Google Cloud project ID.
  • SERVICE with the name of your service.

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

    spec:
      containers:
      - image: gcr.io/cloudrun/hello
        ports:
        - containerPort: PORT
    

    Replace

    • PORT with the port to send requests to.
  3. Replace the service with its new configuration using the following command:

    gcloud beta run services replace service.yaml

Configuring the container entrypoint command and arguments

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.

You can set entrypoint command and arguments using the Cloud 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 & DEPLOY NEW REVISION.

  3. Click SHOW ADVANCED SETTINGS > CONTAINER.

    image

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

  5. 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 gcr.io/PROJECT-ID/SERVICE --command COMMAND --args ARG1,ARG-N

Replace

  • PROJECT-ID with your Google Cloud project ID.
  • SERVICE with name of your service.

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.

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 beta 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: gcr.io/cloudrun/hello
        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.
  3. Replace the service with its new configuration using the following command:

    gcloud beta run services replace service.yaml