Firebase "Container Healthcheck failed" (gen2 functions) in CI
Second-generation functions run on Cloud Run. After deploy, the platform starts the container and waits for it to listen. A crash on startup or a slow init makes the healthcheck fail, and the deploy is rolled back.
What this error means
A gen2 functions deploy fails with "Error: Container Healthcheck failed. The user-provided container failed to start and listen on the port defined provided by the PORT environment variable."
Error: Container Healthcheck failed. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable.Common causes
The function throws during cold start
Top-level code that reads missing config or a bad import crashes the container before it can listen.
Initialization exceeds the startup window
Slow module load or a blocking network call at import time can push past the healthcheck timeout.
How to fix it
Move heavy work out of module load
- Read config and open connections inside the handler, not at import time.
- Check Cloud Run logs for the startup crash the healthcheck reports.
- Redeploy once the container starts cleanly.
firebase deploy --only functions:api --project my-project --debugSet required env before startup
Provide the runtime config the function reads so cold start does not throw, using functions params or environment configuration.
How to prevent it
- Keep module-load work minimal so cold start is fast and safe.
- Set all required runtime configuration before deploy.
- Check Cloud Run startup logs when a healthcheck fails.