📖 Scenario: You are working as a cloud engineer for a small company. They want to deploy a simple web service that responds to HTTP requests. You will use Google Cloud Run, a service that runs containers without managing servers.
🎯 Goal: Build a Cloud Run service by creating a container image, configuring the service, deploying it, and setting the service to allow public access.
📋 What You'll Learn
Create a Dockerfile with a simple web server
Set a service name variable for deployment
Deploy the container image to Cloud Run using the service name
Configure the Cloud Run service to allow unauthenticated (public) access
💡 Why This Matters
🌍 Real World
Cloud Run is used to deploy containerized applications quickly without managing servers, ideal for scalable web services.
💼 Career
Cloud engineers and developers use Cloud Run to deploy and manage serverless container services in production environments.
Progress0 / 4 steps
1
Create a Dockerfile with a simple web server
Create a file named Dockerfile with these exact lines to run a simple Python web server: FROM python:3.12-slim RUN pip install flask COPY app.py /app.py CMD ["python", "/app.py"] Also create app.py with this exact content: from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello from Cloud Run!' if __name__ == '__main__': app.run(host='0.0.0.0', port=8080)
GCP
Hint
Use the official Python 3.12 slim image. Install Flask. Copy your app.py file. Use CMD to run the app.
2
Set a service name variable for deployment
In your terminal or deployment script, create a variable called SERVICE_NAME and set it to hello-cloud-run exactly. This will be the name of your Cloud Run service.
GCP
Hint
Use the exact variable name SERVICE_NAME and assign the string hello-cloud-run.
3
Deploy the container image to Cloud Run using the service name
Write the exact gcloud command to deploy your container image to Cloud Run using the variable SERVICE_NAME. Use the image gcr.io/YOUR_PROJECT_ID/hello-cloud-run (replace YOUR_PROJECT_ID with your project ID). Deploy to region us-central1 and allow unauthenticated access. The command must include gcloud run deploy $SERVICE_NAME with the correct flags.
GCP
Hint
Use the gcloud run deploy command with the service name variable and the correct image path. Include region and allow unauthenticated flags.
4
Configure the Cloud Run service to allow unauthenticated (public) access
Add the IAM policy binding command to allow all users to invoke the Cloud Run service named $SERVICE_NAME in region us-central1. Use the exact command starting with gcloud run services add-iam-policy-binding $SERVICE_NAME and include --member="allUsers" and --role="roles/run.invoker".
GCP
Hint
This command makes your Cloud Run service public by allowing anyone to invoke it.
Practice
(1/5)
1. What is the main benefit of using Cloud Run for your applications?
easy
A. You must manually scale your application.
B. You don't need to manage servers or infrastructure.
C. It only runs applications written in Python.
D. You need to configure virtual machines yourself.
Solution
Step 1: Understand Cloud Run's server management
Cloud Run automatically manages the servers, so you don't have to.
Step 2: Compare other options
Manual scaling and VM configuration are not needed with Cloud Run.
Final Answer:
You don't need to manage servers or infrastructure. -> Option B
Quick Check:
Serverless = No server management [OK]
Hint: Cloud Run means no server setup needed [OK]
Common Mistakes:
Thinking you must manage servers manually
Believing Cloud Run only supports one language
Confusing Cloud Run with VM services
2. Which gcloud command correctly deploys a container image to Cloud Run?
easy
A. gcloud run deploy --image gcr.io/my-project/my-image
B. gcloud compute instances create --image gcr.io/my-project/my-image
C. gcloud app deploy --image gcr.io/my-project/my-image
D. gcloud container clusters create --image gcr.io/my-project/my-image
Solution
Step 1: Identify the correct service for deploying containers
Cloud Run uses gcloud run deploy to deploy container images.
Step 2: Eliminate other commands
compute instances is for VMs, app deploy is for App Engine, and container clusters create is for Kubernetes clusters.
Final Answer:
gcloud run deploy --image gcr.io/my-project/my-image -> Option A
Quick Check:
Cloud Run deploy = gcloud run deploy [OK]
Hint: Use 'gcloud run deploy' for Cloud Run containers [OK]
Common Mistakes:
Using compute or app commands instead of run
Confusing Kubernetes cluster commands with Cloud Run
Missing the --image flag
3. Given this Cloud Run service configuration snippet, what happens when traffic increases?
A. Cloud Run automatically creates more instances to handle the traffic.
B. The service crashes because CPU is limited to 1.
C. You must manually add more instances in the config.
D. Traffic is rejected when CPU limit is reached.
Solution
Step 1: Understand Cloud Run scaling behavior
Cloud Run automatically scales container instances based on incoming traffic.
Step 2: Analyze resource limits
CPU and memory limits set max per instance but do not prevent scaling.
Final Answer:
Cloud Run automatically creates more instances to handle the traffic. -> Option A
Quick Check:
Auto scaling = more instances on traffic rise [OK]
Hint: Cloud Run scales instances automatically with traffic [OK]
Common Mistakes:
Thinking CPU limit stops scaling
Believing manual scaling is required
Assuming traffic is rejected on resource limits
4. You deployed a Cloud Run service but get an error: Container failed to start. What is a likely cause?
medium
A. The container image is too large to deploy.
B. You forgot to set the CPU limit in the deployment.
C. The container image does not have a listening port configured.
D. Cloud Run requires a VM instance to be created first.
Solution
Step 1: Check container requirements for Cloud Run
Cloud Run requires the container to listen on a port for incoming requests.
Step 2: Evaluate other options
CPU limits are optional, Cloud Run is serverless (no VM setup), and image size usually causes warnings, not start failure.
Final Answer:
The container image does not have a listening port configured. -> Option C
Quick Check:
Listening port missing = start failure [OK]
Hint: Containers must listen on a port for Cloud Run [OK]
Common Mistakes:
Assuming VM setup is needed
Blaming CPU limits for start failure
Thinking image size causes start errors
5. You want to deploy a Cloud Run service that scales down to zero when idle but also supports up to 10 concurrent requests per instance. Which configuration is correct?
hard
A. Set --concurrency=1 and --min-instances=10 to scale down to zero.
B. Set --min-instances=1 and --concurrency=10 to scale to zero.
C. Set --max-instances=10 and --concurrency=1 to allow 10 concurrent requests.
D. Set --concurrency=10 and deploy normally; Cloud Run scales to zero automatically.
Solution
Step 1: Understand concurrency and scaling in Cloud Run
Concurrency controls how many requests one instance handles; setting it to 10 allows 10 requests per instance.
Step 2: Understand scaling to zero behavior
Cloud Run automatically scales down to zero when idle unless --min-instances is set above zero.
Final Answer:
Set --concurrency=10 and deploy normally; Cloud Run scales to zero automatically. -> Option D
Quick Check:
Concurrency 10 + no min-instances = scale to zero [OK]
Hint: No min-instances means auto scale to zero [OK]
Common Mistakes:
Setting min-instances prevents scaling to zero
Confusing max-instances with concurrency
Assuming concurrency 1 means 10 requests
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.