How to Fix Docker Timeout Error on Google Cloud Run
Troubleshooting: Fixing “Docker Timeout Error” on Google Cloud Run
1. The Root Cause
The “Docker Timeout Error” on Google Cloud Run typically manifests during the container image build phase, which is implicitly handled by Google Cloud Build when you deploy directly from source. This error occurs when your docker build process exceeds Cloud Build’s default timeout duration, which is 10 minutes (600 seconds).
2. Quick Fix (CLI)
To immediately resolve a build timeout, explicitly build your Docker image with an extended timeout using gcloud builds submit, then deploy the pre-built image.
-
Build the Docker image with an extended timeout: (Replace
PROJECT_IDwith your Google Cloud Project ID andSERVICE_NAMEwith your Cloud Run service name.1200ssets the timeout to 20 minutes.)gcloud builds submit --tag gcr.io/PROJECT_ID/SERVICE_NAME:latest --timeout=1200s . -
Deploy the pre-built image to Cloud Run: (Replace
SERVICE_NAMEandREGIONwith your service name and desired Google Cloud region.)gcloud run deploy SERVICE_NAME --image gcr.io/PROJECT_ID/SERVICE_NAME:latest --platform managed --region REGION --allow-unauthenticated
3. Configuration Check
For a permanent solution, define a cloudbuild.yaml file in your project root to explicitly configure your build process and override the default timeout.
File to edit: cloudbuild.yaml (create it if it doesn’t exist)
What to change: Add or modify the timeout field at the top level of the cloudbuild.yaml.
# cloudbuild.yaml
timeout: 1200s # Extend to 20 minutes (1200 seconds) or more as needed
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME', '.']
env:
- 'DOCKER_BUILDKIT=1' # Optional: Enable BuildKit for potentially faster builds and advanced features
images:
- 'gcr.io/$PROJECT_ID/$_SERVICE_NAME'
When you next deploy using gcloud run deploy --source ., Cloud Build will automatically pick up this cloudbuild.yaml and use the specified timeout.
4. Verification
After implementing the quick fix or configuring your cloudbuild.yaml, re-trigger a deployment to confirm the build now completes successfully.
Command to verify:
If you used the cloudbuild.yaml configuration, simply deploy from source:
gcloud run deploy SERVICE_NAME --source . --platform managed --region REGION
Monitor the output and the Cloud Build logs in the Google Cloud Console to ensure the build process completes without the “Docker Timeout Error.”