Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How can I host multiple containers(sidecar) in cloud run

I'm trying to deploy multiple containers(sidecar) in cloud run by following the sidecar docs; 

The service I want to deploy is here

In my attempt to deploy the service, I have created the below service.yaml file;

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
annotations:
name: bhadala-blnk2
spec:
template:
spec:
containers:
- image: jerryenebeli/blnk:latest
ports:
- containerPort: 5001
- image: redis:7.2.4
- image: postgres:16
- image: jerryenebeli/blnk:0.8.0
- image: typesense/typesense:0.23.1
- image: jaegertracing/all-in-one:latest
And then I run the command;

gcloud run services replace service.yaml --region us-east1

But then  got this error in cloud run;
"Revision 'bhadala-blnk2-00002-27r' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short."


I'm new to Cloud run. Please help me deploy this service in cloud run and tell me where my service.yaml is doing wrong.

0 26 1,586
26 REPLIES 26

This is the service I want to deploy is here

Hi, @Kamal_Moha.

Cloud Run supports the sidecar pattern for deploying multiple containers simultaneously. Have you already checked the documentation - Cloud Run now supports sidecar deployments — monitoring agents, proxies and more? It includes all the necessary steps.

Regards,
Mokit

Hi @mokit, YES I have tried all the steps mentioned in the sidecar docs
But I get this error; 
"Revision 'bhadala-blnk-00002-2jc' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short"

Kamal_Moha_0-1737581009603.png

I'm stuck on this for the last 5 days and I don't know what to do. Please @mokit help me to deploy this multi container service 

 
 
 
 
 
 

Is your application running on port 8080? Also, could you please share the Cloud Run application logs also?

Here is the link to the logs https://cloudlogging.app.goo.gl/cMhzDc12ng5NL8MV8

I'm not building any docker image, but rather getting the image(s) from docker hub and then trying to run it in cloud run. This is the main(ingress) container; jerryenebeli/blnk:latest

Before hosting it to cloud run, I run this application on my local machine using docker compose and it worked well. Here is the Dockerfile exposing 8080

FROM golang:1.21-alpine as build-env
WORKDIR /go/src/blnk

COPY . .

RUN go build -o /blnk ./cmd/*.go

FROM debian:bullseye-slim

# Install pg_dump version 16
RUN apt-get update && apt-get install -y wget gnupg2 lsb-release && \
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
apt-get update && \
apt-get install -y postgresql-client-16 && \
rm -rf /var/lib/apt/lists/*

COPY --from=build-env /blnk /usr/local/bin/blnk

RUN chmod +x /usr/local/bin/blnk

CMD ["blnk", "start"]

EXPOSE 8080

 

 
 
 

I'm unable to access the logs using the provided URL since I'm not working with your GCP project. Could you please paste the log output here in the comment thread?

In your description above, you’ve set containerPort: 5001. I believe this is incorrect. You should set containerPort: 8080 and also configure the PORT environment variable to 8080.

The exposed port element is confusing because when I run this application locally, the exposed port is 5001 and not 8080. Even when you look at the documentation for this service, they say port 5001 is the port to expose.

That's why I'm testing port 5001 vs 8080 to see what works. But when I run any of them, I get the same error in cloud run

 
 
 
 

@Kamal_Moha, Let’s focus on one point. If you're using port 5001, you need to set it in the application server, the Docker expose port, and the containerPort in Cloud Run configuration. Also, add the environment variable PORT=5001. The same applies if you're planning to use port 8080, just replace the port number accordingly that mentioned for 5001.

YES sir, I agree, I'm focusing on port 5001 & picking that moving forward. 

 
 
 

Mr @mokit, here is the error from the logs 

{
insertId: "67915d9c000d6a0afc267d90"
labels: {2}
logName: "projects/witaxipay-bhadala/logs/run.googleapis.com%2Fvarlog%2Fsystem"
receiveTimestamp: "2025-01-22T21:05:33.027745157Z"
resource: {
labels: {5}
type: "cloud_run_revision"
}
severity: "ERROR"
textPayload: "Default STARTUP TCP probe failed 1 time consecutively for container "server" on port 8080. The instance was not started."
timestamp: "2025-01-22T21:05:32.879114Z"

 
 
 

Have you had a chance to review my last message in this thread?

YES I have. I visited the logs, clicked Actions dropdown > Download > I'm pasting the entire logs, please tell me if this is what you're looking for.  

 

 

 

 

 

[
  {
    "protoPayload": {
      "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
      "status": {
        "code": 9,
        "message": "Ready condition status changed to False for Revision bhadala-blnk-00003-5bg with message: The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start"
      },
      "serviceName": "run.googleapis.com",
      "methodName": "/Services.ReplaceService",
      "resourceName": "namespaces/witaxipay-bhadala/revisions/bhadala-blnk-00003-5bg",
      "response": {
        "metadata": {
          "name": "bhadala-blnk-00003-5bg",
          "namespace": "288219978516",
          "selfLink": "/apis/serving.knative.dev/v1/namespaces/288219978516/revisions/bhadala-blnk-00003-5bg",
          "uid": "57e4d318-cbdb-4ca5-b785-77130bd2b81e",
          "resourceVersion": "AAYsU0v1Q50",
          "generation": 1,
          "creationTimestamp": "2025-01-22T22:48:33.850460Z",
          "labels": {
            "client.knative.dev/nonce": "f21de577-3682-440e-9ec6-2e5bce70d3af",
            "serving.knative.dev/configuration": "bhadala-blnk",
            "serving.knative.dev/configurationGeneration": "3",
            "serving.knative.dev/service": "bhadala-blnk",
            "serving.knative.dev/serviceUid": "950cef21-63ce-4b98-b2de-13e6573b4af0",
            "serving.knative.dev/route": "bhadala-blnk",
            "cloud.googleapis.com/location": "us-east1",
            "run.googleapis.com/startupProbeType": "Custom"
          },
          "annotations": {
            "run.googleapis.com/client-name": "cloud-console",
            "run.googleapis.com/startup-cpu-boost": "true",
            "autoscaling.knative.dev/minScale": "1",
            "run.googleapis.com/operation-id": "9a9cff38-a0ad-4fc3-bf0c-e4c090f13d01",
            "autoscaling.knative.dev/maxScale": "5"
          },
          "ownerReferences": [
            {
              "kind": "Configuration",
              "name": "bhadala-blnk",
              "uid": "8a54be0c-1b36-4a91-9719-bee66b090b75",
              "apiVersion": "serving.knative.dev/v1",
              "controller": true,
              "blockOwnerDeletion": true
            }
          ]
        },
        "apiVersion": "serving.knative.dev/v1",
        "kind": "Revision",
        "spec": {
          "containerConcurrency": 80,
          "timeoutSeconds": 300,
          "serviceAccountName": "288219978516-compute@developer.gserviceaccount.com",
          "containers": [
            {
              "name": "server",
              "image": "mirror.gcr.io/jerryenebeli/blnk@sha256:1e34412eafd9a9533a112919d26a24d56a37219741ce66159890e50777850c11",
              "ports": [
                {
                  "name": "http1",
                  "containerPort": 5001
                }
              ],
              "resources": {
                "limits": {
                  "cpu": "1000m",
                  "memory": "512Mi"
                }
              },
              "volumeMounts": [
                {
                  "name": "blnk_json",
                  "mountPath": "/blnk_json"
                }
              ],
              "livenessProbe": {
                "initialDelaySeconds": 30,
                "timeoutSeconds": 1,
                "periodSeconds": 10,
                "failureThreshold": 3,
                "httpGet": {
                  "path": "/health",
                  "port": 5001
                }
              },
              "startupProbe": {
                "initialDelaySeconds": 30,
                "timeoutSeconds": 240,
                "periodSeconds": 240,
                "failureThreshold": 1,
                "tcpSocket": {
                  "port": 5001
                }
              }
            },
            {
              "name": "worker",
              "image": "mirror.gcr.io/jerryenebeli/blnk@sha256:20c1d8895a8c5ccfa155f337211c5adbe32574948cbb6813f5bf6299e63ba79f",
              "command": [
                "blnk",
                "workers"
              ],
              "resources": {
                "limits": {
                  "cpu": "1000m",
                  "memory": "512Mi"
                }
              },
              "volumeMounts": [
                {
                  "name": "blnk_json",
                  "mountPath": "/blnk_json"
                }
              ]
            },
            {
              "name": "migration-job",
              "image": "mirror.gcr.io/jerryenebeli/blnk@sha256:20c1d8895a8c5ccfa155f337211c5adbe32574948cbb6813f5bf6299e63ba79f",
              "command": [
                "blnk",
                "migrate",
                "up"
              ],
              "resources": {
                "limits": {
                  "cpu": "1000m",
                  "memory": "512Mi"
                }
              },
              "volumeMounts": [
                {
                  "name": "blnk_json",
                  "mountPath": "/blnk_json"
                }
              ]
            }
          ],
          "volumes": [
            {
              "name": "blnk_json",
              "secret": {
                "secretName": "blnk_json",
                "items": [
                  {
                    "key": "latest",
                    "path": "blnk_json"
                  }
                ]
              }
            }
          ]
        },
        "status": {
          "observedGeneration": 1,
          "conditions": [
            {
              "type": "Ready",
              "status": "False",
              "reason": "HealthCheckContainerError",
              "message": "The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
              "lastTransitionTime": "2025-01-22T22:48:48.536477Z"
            },
            {
              "type": "ContainerHealthy",
              "status": "False",
              "reason": "HealthCheckContainerError",
              "message": "The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
              "lastTransitionTime": "2025-01-22T22:48:48.536477Z"
            },
            {
              "type": "ContainerReady",
              "status": "True",
              "message": "Container image import completed.",
              "lastTransitionTime": "2025-01-22T22:48:36.750153Z"
            },
            {
              "type": "MinInstancesProvisioned",
              "status": "Unknown",
              "reason": "MinInstancesWarming",
              "lastTransitionTime": "2025-01-22T22:48:39.449402Z"
            },
            {
              "type": "ResourcesAvailable",
              "status": "True",
              "message": "Revision deployment finished in 2.7s. Checking container health.",
              "lastTransitionTime": "2025-01-22T22:48:39.449402Z"
            },
            {
              "type": "Retry",
              "status": "True",
              "reason": "ImmediateRetry",
              "message": "System will retry after 0:00:00 from lastTransitionTime for attempt 0.",
              "lastTransitionTime": "2025-01-22T22:48:39.449402Z",
              "severity": "Info"
            }
          ],
          "logUrl": "https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22",
          "containerStatuses": [
            {
              "name": "server",
              "imageDigest": "mirror.gcr.io/jerryenebeli/blnk@sha256:1e34412eafd9a9533a112919d26a24d56a37219741ce66159890e50777850c11"
            },
            {
              "name": "worker",
              "imageDigest": "mirror.gcr.io/jerryenebeli/blnk@sha256:20c1d8895a8c5ccfa155f337211c5adbe32574948cbb6813f5bf6299e63ba79f"
            },
            {
              "name": "migration-job",
              "imageDigest": "mirror.gcr.io/jerryenebeli/blnk@sha256:20c1d8895a8c5ccfa155f337211c5adbe32574948cbb6813f5bf6299e63ba79f"
            }
          ],
          "desiredReplicas": 1
        },
        "@type": "type.googleapis.com/google.cloud.run.v1.Revision"
      }
    },
    "insertId": "uuz2v8c350",
    "resource": {
      "type": "cloud_run_revision",
      "labels": {
        "service_name": "bhadala-blnk",
        "configuration_name": "bhadala-blnk",
        "project_id": "witaxipay-bhadala",
        "location": "us-east1",
        "revision_name": "bhadala-blnk-00003-5bg"
      }
    },
    "timestamp": "2025-01-22T22:48:48.552123Z",
    "severity": "ERROR",
    "logName": "projects/witaxipay-bhadala/logs/cloudaudit.googleapis.com%2Fsystem_event",
    "receiveTimestamp": "2025-01-22T22:48:49.465048968Z"
  },
  {
    "protoPayload": {
      "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
      "status": {
        "code": 9,
        "message": "Ready condition status changed to False for Service bhadala-blnk with message: Revision 'bhadala-blnk-00003-5bg' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start"
      },
      "serviceName": "run.googleapis.com",
      "methodName": "/Services.ReplaceService",
      "resourceName": "namespaces/witaxipay-bhadala/services/bhadala-blnk",
      "response": {
        "metadata": {
          "name": "bhadala-blnk",
          "namespace": "288219978516",
          "selfLink": "/apis/serving.knative.dev/v1/namespaces/288219978516/services/bhadala-blnk",
          "uid": "950cef21-63ce-4b98-b2de-13e6573b4af0",
          "resourceVersion": "AAYsU0v3JOI",
          "generation": 3,
          "creationTimestamp": "2025-01-22T17:58:05.141602Z",
          "labels": {
            "cloud.googleapis.com/location": "us-east1"
          },
          "annotations": {
            "run.googleapis.com/client-name": "cloud-console",
            "run.googleapis.com/operation-id": "9a9cff38-a0ad-4fc3-bf0c-e4c090f13d01",
            "run.googleapis.com/ingress": "all",
            "run.googleapis.com/ingress-status": "all",
            "run.googleapis.com/minScale": "1",
            "run.googleapis.com/urls": "[\"https://bhadala-blnk-288219978516.us-east1.run.app\"]"
          }
        },
        "apiVersion": "serving.knative.dev/v1",
        "kind": "Service",
        "spec": {
          "template": {
            "metadata": {
              "labels": {
                "client.knative.dev/nonce": "f21de577-3682-440e-9ec6-2e5bce70d3af",
                "run.googleapis.com/startupProbeType": "Custom"
              },
              "annotations": {
                "autoscaling.knative.dev/maxScale": "5",
                "autoscaling.knative.dev/minScale": "1",
                "run.googleapis.com/client-name": "cloud-console",
                "run.googleapis.com/startup-cpu-boost": "true"
              }
            },
            "spec": {
              "containerConcurrency": 80,
              "timeoutSeconds": 300,
              "serviceAccountName": "288219978516-compute@developer.gserviceaccount.com",
              "containers": [
                {
                  "name": "server",
                  "image": "jerryenebeli/blnk:latest",
                  "ports": [
                    {
                      "name": "http1",
                      "containerPort": 5001
                    }
                  ],
                  "resources": {
                    "limits": {
                      "cpu": "1000m",
                      "memory": "512Mi"
                    }
                  },
                  "volumeMounts": [
                    {
                      "name": "blnk_json",
                      "mountPath": "/blnk_json"
                    }
                  ],
                  "livenessProbe": {
                    "initialDelaySeconds": 30,
                    "timeoutSeconds": 1,
                    "periodSeconds": 10,
                    "failureThreshold": 3,
                    "httpGet": {
                      "path": "/health",
                      "port": 5001
                    }
                  },
                  "startupProbe": {
                    "initialDelaySeconds": 30,
                    "timeoutSeconds": 240,
                    "periodSeconds": 240,
                    "failureThreshold": 1,
                    "tcpSocket": {
                      "port": 5001
                    }
                  }
                },
                {
                  "name": "worker",
                  "image": "jerryenebeli/blnk:0.8.0",
                  "command": [
                    "blnk",
                    "workers"
                  ],
                  "resources": {
                    "limits": {
                      "cpu": "1000m",
                      "memory": "512Mi"
                    }
                  },
                  "volumeMounts": [
                    {
                      "name": "blnk_json",
                      "mountPath": "/blnk_json"
                    }
                  ]
                },
                {
                  "name": "migration-job",
                  "image": "jerryenebeli/blnk:0.8.0",
                  "command": [
                    "blnk",
                    "migrate",
                    "up"
                  ],
                  "resources": {
                    "limits": {
                      "cpu": "1000m",
                      "memory": "512Mi"
                    }
                  },
                  "volumeMounts": [
                    {
                      "name": "blnk_json",
                      "mountPath": "/blnk_json"
                    }
                  ]
                }
              ],
              "volumes": [
                {
                  "name": "blnk_json",
                  "secret": {
                    "secretName": "blnk_json",
                    "items": [
                      {
                        "key": "latest",
                        "path": "blnk_json"
                      }
                    ]
                  }
                }
              ]
            }
          },
          "traffic": [
            {
              "percent": 100,
              "latestRevision": true
            }
          ]
        },
        "status": {
          "observedGeneration": 3,
          "conditions": [
            {
              "type": "Ready",
              "status": "False",
              "reason": "HealthCheckContainerError",
              "message": "Revision 'bhadala-blnk-00003-5bg' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
              "lastTransitionTime": "2025-01-22T22:48:48.584996Z"
            },
            {
              "type": "ConfigurationsReady",
              "status": "True",
              "message": "The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
              "lastTransitionTime": "2025-01-22T22:48:48.576350Z"
            },
            {
              "type": "RoutesReady",
              "status": "False",
              "reason": "HealthCheckContainerError",
              "message": "Revision 'bhadala-blnk-00003-5bg' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=witaxipay-bhadala&resource=cloud_run_revision/service_name/bhadala-blnk/revision_name/bhadala-blnk-00003-5bg&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22bhadala-blnk%22%0Aresource.labels.revision_name%3D%22bhadala-blnk-00003-5bg%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
              "lastTransitionTime": "2025-01-22T22:48:48.584996Z"
            }
          ],
          "latestReadyRevisionName": "bhadala-blnk-00003-5bg",
          "latestCreatedRevisionName": "bhadala-blnk-00003-5bg"
        },
        "@type": "type.googleapis.com/google.cloud.run.v1.Service"
      }
    },
    "insertId": "hrb28oc4sw",
    "resource": {
      "type": "cloud_run_revision",
      "labels": {
        "location": "us-east1",
        "configuration_name": "",
        "service_name": "bhadala-blnk",
        "project_id": "witaxipay-bhadala",
        "revision_name": ""
      }
    },
    "timestamp": "2025-01-22T22:48:48.679322Z",
    "severity": "ERROR",
    "logName": "projects/witaxipay-bhadala/logs/cloudaudit.googleapis.com%2Fsystem_event",
    "receiveTimestamp": "2025-01-22T22:48:48.716740691Z"
  }
]

 

 

 

 

 

 
 
 
 
 
 
 
 
 

Have you checked if the container image (mirror.gcr.io/jerryenebeli/blnk@sha256:20c1d8895a8c5ccfa155f337211c5adbe32574948cbb6813f5bf6299e63ba79f) runs successfully on your local machine in the port 5001?

YES the container image jerryenebeli/blnk@sha256:20c1d8895a8c5ccfa155f337211c5adbe32574948cbb6813f5bf6299e63ba79f runs successfully on my local machine. It renders an API application on port 5001

 
 
 

Using this image, can you create a new separate Cloud Run? Let me know if you encounter any errors.

I ran this image in a separate cloud run and I get the same error;

"Revision 'blnk-server-solo-00001-lx9' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=5001 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended"

I would like to give you some context into this service/application I'm trying to run. This application(when working properly) renders an API that's able to handle requests. But for this application to run as expected, it needs managed database instances of Postgres & Redis connected to it. When I was running it locally with docker compose, I was using docker images of Postgres & Redis. 

I have done more research into this and found out that cloud run doesn't support databases. Cloud run is for http services. 

However, through Google's Cloud SQL, I was able to create a Postgres instance.  And use Memorystore for Redis to create a Redis instance. 

Surely, the API portion can be hosted in cloud run, but that API portion needs these Databases connected.

Considering all of this Mr @mokit, what advice do you have for me and how can I bring these pieces together. I have personally opted for Cloud run because it's cheap(with a free tier) and relatively straightforward to have something up & running. 

What advice do you have for me?

 

 
 
 
 
 
 

Unfortunately, I wasn't aware that the database service can't be run directly on Cloud Run, as I haven't tested it before. I plan to explore this in the future. If possible, could you provide some documentation on this?

Let's move on to your queries. Yes, you can use Cloud Run for your backend service as a web server to serve the API. For the database, you can select Cloud SQL (since you're planning to use PostgreSQL) and for caching, you can choose Memorystore for Redis. However, I do have a few more questions regarding this architecture before we proceed.

Could you please let me know what you're planning to use the system for? Is it for a demo or an MVP project. Or are you planning to use it as a business system in production?

If you're planning to use this as a production system for regular use, how many users do you expect to access it? Do you have any specific requirements regarding system cost, latency or future scalability?

I have found the Database element not being a proper thing for Cloud run via Stackoveflow & reddit forums during my research. Will ook up some documentation on this & will share.

YES I have actually created a Postgres instance in Cloud SQL & a Redis instance(in MemoryStore) with the aim of using it in Cloud run for this service.

Let me share the goal with this. On my end, I want to host this service for temporary sandbox testing purposes. My intention is to spin something quickly, make tests and then stop after the purpose is achieved. Surely if I find cloud run performing well, then can decide to take to it to prod to about 50 users. 

 
 
 

Since this system is for testing purposes, I'd mostly recommend using a GCP VM (https://cloud.google.com/products/compute?hl=en). It's similar to your local machine, where you can install Docker and Docker Compose. Then, you can bring up the entire application with a single command: docker-compose up.

OK @mokit, thanks a lot. I didn't know that

I will go and setup a test application with GCE VM. This should get me started

Though I really want to also deploy this to Cloud run  for scale with real users. 

 
 
 

@Kamal_Moha  Could you please provide me with the terminal commands you used to create and push the container image to the Artifact/Container registry? This would help me resolve your issue.

I suspect that you may be missing the Supported languages and images while creating the container image.

If my hunch is correct, then you can add the --platform linux/amd64 argument when generating your Docker build. Here is a sample command that you can adjust to fit your development environment:

docker buildx build -t gcr.io/{project_id}/{image_name}:{tag_name} --platform linux/amd64 .

@aroon4uu I wasn't actually building any containers on Artifact Container Registry, but rather using images directly from docker hub. 

At a high level what I'm trying to accomplish is to host an API service connected to Postgres & Redis instances in cloud run. The idea is to have the API portion hosted in cloud run as the ingress container, and other elements as sidecar containers. 

Is --platform linux/amd64 required for docker hub containers? If yes, how can I do it then?

 
 
 

Have you tried changing the container startup order? Try with second container starts after the first.

To achieve this, add a health check to the second container with these settings:

  • Initial Delay: Set this to 12-15 seconds or longer, depending on the first container's startup time.
  • Timeout: 5 seconds
  • Failure Threshold: 3

I have created one separate blog for this on medium. Check this might help you more.

Screenshot 2025-01-27 at 1.45.18 PM.png

@aroon4uu thanks your article was helpful. The application I want to deploy is an API service that handles http requests. The docs on how to deploy this service is here. Unfortunately, the deployment mainly focuses on a local deployment(using docker compose) and then kubernetes. I want to deploy the service using cloud run.

I have picked cloud run because it's scalable, easy to set u and much cheaper than GKE(Kubernetes Engine)

Have a look at my cloud run service architecture;

Kamal_Moha_0-1738100970836.png

I will be running the API server as the main container running on port 5001. Then a worker image that basically runs a command. Then I will Google Secret Manager to create a config file(blnk.json) that contains database connections. For databases, I have opted to host the PostgreSQL & Redis database instances using Digital Ocean because they're cheaper than Google's. 

I will mount blnk.json as a volume for the containers. This is how blnk.json file will look like;

 

{
  "project_name": "Blnk",
  "data_source": {
    "dns": "postgres://blnk_user:StrongPass123@blnk-do-postgres-nyc3-12345.db.ondigitalocean.com:25060/blnk?sslmode=require"
  },
  "redis": {
    "dns": "rediss://:RedisPass456@blnk-do-redis-nyc3-67890.db.ondigitalocean.com:6379"
  },
  "server": {
    "port": "5001"
  }
}

 

Here's cloud run deployment service.yaml file;

 

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: blnk-service
spec:
  template:
    metadata:
      annotations:
        run.googleapis.com/container-ports: "server:5001"
        run.googleapis.com/vpc-access-connector: "do-vpc-connector" # Optional
    spec:
      containers:
      - name: server
        image: jerryenebeli/blnk:0.7.4
        command: ["sh", "-c", "blnk migrate up && blnk server"]
        ports:
        - containerPort: 5001
        volumeMounts:
        - name: config
          mountPath: /blnk.json
          subPath: blnk.json

      - name: worker
        image: jerryenebeli/blnk:0.7.4
        command: ["blnk", "workers"]
        volumeMounts:
        - name: config
          mountPath: /blnk.json
          subPath: blnk.json

      volumes:
      - name: config
        secret:
          secretName: blnk-config
          items:
          - key: latest
            path: blnk.json

 

Will run the below command to make the deployment to cloud run

 

gcloud run services replace service.yaml

 

@aroon4uu and @mokit please what you guys think of this. Thanks!

 
 
 

@mokit quick update; As you've recommended, I have been able to deploy the application in a GCE VM Instance using docker compose up to bring up all the required containers within the VM. The experience was straightforward just like a local implementation. Thanks for your advice.

Though, I really want to have my service in cloud run & learn how to host a sidecar container in cloud run. I'm sure cloud run is able to host the API portion of this(as the ingress container) because the API part is basically a http service. But then how can I have a redis & postgres instance in cloud run coz for the entire application to run, it needs redis & postgres.

And then most importantly, how can I solve this error with the port when deploying to cloud run?