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

cannot deploy GC function due to container health check

I am constantly getting this error when I try to deploy my Cloud Function:

Could not create or update Cloud Run service move-docai-to-bigquery, Container Healthcheck failed. Revision 'move-docai-to-bigquery-00012-xuv' 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. Logs for this revision might contain more information

 

It looks like it has a problem with the container instance and its port settings. BUT I do not know how to fix this. Is there anybody who had a similar issue before ?

 

5 6 7,925
6 REPLIES 6

Hi @andrehilden,

Welcome to Google Cloud Community!

Your Cloud Function deployment fails due to a "Container Healthcheck failed" error.

Cause: The container instance in Cloud Run is unable to start and listen on the defined port (8080).

Steps to Fix:

  1. Analyze Logs: Dive into the logs for specific errors regarding port binding, startup, or dependencies.
  2. Verify Port Configuration: Ensure your application listens on port 8080 (or adjust the PORT environment variable).
  3. Examine Startup Process: Confirm quick and error-free application startup within the health check timeout.
  4. Review Dependencies: Verify and check accessibility of all required dependencies.
  5. Consider Custom Health Check: If needed, define a custom health check endpoint.

Additional Tips:

  • Test locally to isolate the issue.
  • Review deployment settings for errors.
  • Search for similar problems online.
  • Contact Google Cloud support if needed.

I have the same problem as @andrehilden .I do not understand this answer by @christianpaula .  I use 
```
gcloud functions deploy python-http-function \
--gen2 \
--runtime=python311 \
--region=australia-southeast1 \
--source=. \
--entry-point=hello_http \
--trigger-http \
--allow-unauthenticated
```

The documentation says that the gcloud deploy functionality takes care of the port.  How can I "Ensure my application listens on port 8080 (or adjust the PORT environment variable)."  If you mean my local environment, how does that help with the Cloud Console?

Follow up: I tried to set the PORT using os.getenv('PORT', 8080).  Then I did gcloud functions deploy again.  This time the error was different:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Could not create or update Cloud Run service python-http-function, Container Healthcheck failed. Revision 'python-http-function-00001-bof' 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. Logs for this revision might contain more information.

Do you have any advice?

I had the same error, and it was solved by adding the required dependencies, which I had forgotten to include in the requirements.txt file.

 

I had the exact same problem, solved it by fixing the requirements.txt

This error is an example of terrible error messaging. You will get this issue if there is a compile error in your code or if there is a missing package in your cloud functions.  See this Stack Overflow issue: https://stackoverflow.com/questions/76990628/firebase-functions-could-not-create-or-update-cloud-run...