Deploy a containerized app to Cloud Run (serverless) and a traditional VM to Compute Engine. Understand when each is the right choice.
Cloud Run runs Docker containers without managing servers. It scales to zero (no traffic = no cost) and handles scaling automatically.
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]# Build and push to Artifact Registry
gcloud run deploy my-service \
--source . \
--platform managed \
--region us-central1 \
--allow-unauthenticated
# Or build/push manually
gcloud builds submit --tag gcr.io/PROJECT_ID/my-app
gcloud run deploy my-app --image gcr.io/PROJECT_ID/my-app# Create a VM
gcloud compute instances create my-vm \
--machine-type e2-micro \
--zone us-central1-a \
--image-family debian-12 \
--image-project debian-cloud
# SSH into it
gcloud compute ssh my-vm --zone us-central1-a
# Stop when done to avoid charges
gcloud compute instances stop my-vm --zone us-central1-agcloud run deploy --source . auto-builds and deploys from source code.