Question

Difficulty: MediumDeploying Serverless Applications with Cloud Run and Cloud Functions

A software team is deploying an existing internal microservice named `analytics-ingest` to Google Cloud Run using the `gcloud` CLI. The application container is hardcoded to listen for incoming web traffic on port 3000 and does not dynamically adapt to the default `PORT` environment variable. When deployed with default parameters, the service fails health checks because Cloud Run routes requests to port 8080. Which `gcloud run deploy` parameter must be included to resolve this issue?

  1. A
    --container-port=3000
  2. --port=3000Answer
  3. C
    --target-port=3000
  4. D
    --trigger-http

Answer

Use the `--port=3000` flag in the `gcloud run deploy` command to direct Cloud Run to route requests to port 3000 inside the container.
By default, Cloud Run sends requests to port 8080 inside the container and sets the `PORT` environment variable to 8080. If a container application is hardcoded to listen on a non-standard port such as 3000, passing `--port=3000` to `gcloud run deploy` tells Cloud Run to route traffic to port 3000 and sets `PORT=3000` within the container environment.

Step-by-Step Solution

1
Identify the container's listening port requirement
The microservice container listens strictly on port 3000 instead of the Cloud Run default port 8080.
Cloud Run assumes the container listens on port 8080 unless configured otherwise.
2
Select the correct gcloud run deploy flag for port configuration
The `--port` flag explicitly sets the ingress container listening port for Cloud Run.
Passing `--port=3000` instructs Cloud Run to perform container startup checks and send HTTP traffic to port 3000.

Key Concept

Cloud Run Container Port Binding
Rate this question