Skip to content
Back to Cloud Services

GCP Serverless with Cloud Run

Deploy containerized apps to Google Cloud Run with auto-scaling to zero and pay-per-use pricing.

GCPIntermediate

Why

Cloud Run runs any container without Kubernetes complexity. Auto-scales to zero (no idle cost), scales to 1000+ instances, and charges per-request with 100ms granularity.

Best serverless for Dockerized apps.

When

Use Cloud Run when you have Docker images, want serverless without vendor lock-in (containers are portable), and need auto-scale-to-zero. Great for APIs, background workers, and ML inference.

How

1. Install gcloud CLI — gcloud init, gcloud auth login 2. Enable API — gcloud services enable run.googleapis.com 3. Build image — docker build -t gcr.io/PROJECT-ID/myapp . 4. Push image — docker push gcr.io/PROJECT-ID/myapp 5. Deploy — gcloud run deploy myapp --image gcr.io/PROJECT-ID/myapp --region us-central1 6. Configure — set memory, CPU, concurrency, min/max instances, env vars 7. Custom domain — gcloud run domain-mappings create --service myapp --domain api.example.com 8. CI/CD — Cloud Build trigger on git push, auto-deploy on merge

Example

# Dockerfile — any container works FROM node:20-slim WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . CMD ["node", "server.js"] # Deploy with config gcloud run deploy myapp \ --source . \ --region us-central1 \ --memory 512Mi \ --cpu 1 \ --concurrency 80 \ --min-instances 0 \ --max-instances 100 \ --set-env-vars "DATABASE_URL=postgres://..." \ --no-allow-unauthenticated # Cloud Build CI/CD — cloudbuild.yaml steps: - name: gcr.io/cloud-builders/docker args: ["build", "-t", "gcr.io/$PROJECT_ID/myapp", "."] - name: gcr.io/cloud-builders/docker args: ["push", "gcr.io/$PROJECT_ID/myapp"] - name: gcr.io/google.com/cloudsdktool/cloud-sdk args: - run - deploy - myapp - --image - gcr.io/$PROJECT_ID/myapp - --region - us-central1

Common Problems

  • ⚠Cold start 2-8s with min-instances=0 — first request after idle is slow
  • ⚠Request timeout 60s default — long-running requests get killed, set --timeout
  • ⚠Concurrency too high — 1000 concurrent on 512Mi causes OOM, tune per workload
  • ⚠VPC connector needed for private resources — Cloud Run is external by default

Best Practices

  • ✓Set min-instances=1 for latency-critical APIs — eliminates cold starts, costs ~$15/mo
  • ✓Use --cpu-boost for startup — extra CPU during cold start, no extra cost after
  • ✓Keep containers under 100MB — faster cold starts, use multi-stage builds
  • ✓Use Cloud Run jobs (not services) for batch work — no request timeout, up to 24h

FAQ

What is GCP Serverless with Cloud Run and what problem does it solve?

Deploy containerized apps to Google Cloud Run with auto-scaling to zero and pay-per-use pricing. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with GCP Serverless with Cloud Run in 5 minutes?

Two steps to run it: (1) Install gcloud CLI — gcloud init, gcloud auth login; (2) Enable API — gcloud services enable run.googleapis.com. Validate on the free tier first, then wire into production.

What is the #1 pitfall with GCP Serverless with Cloud Run?

The most frequent issue is: Cold start 2-8s with min-instances=0 — first request after idle is slow. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for GCP Serverless with Cloud Run?

Best practices for GCP Serverless with Cloud Run include: Set min-instances=1 for latency-critical APIs — eliminates cold starts, costs ~$15/mo; Use --cpu-boost for startup — extra CPU during cold start, no extra cost after; Keep containers under 100MB — faster cold starts, use multi-stage builds. The first one — "Set min-instances=1 for latency-critical APIs — eliminates cold starts, costs ~$15/mo" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with GCP Serverless with Cloud Run?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most GCP Serverless with Cloud Run options offer a free tier — validate within free quota before scaling.