0
0
GCPcloud~5 mins

Why Cloud Run matters for containers in GCP - Why It Works

Choose your learning style9 modes available
Introduction
Running container apps can be hard because you need to manage servers and scaling. Cloud Run solves this by running containers automatically without you managing servers, so your app just works and scales with demand.
When you want to run a containerized web app without managing servers or infrastructure.
When your app needs to automatically scale up and down based on traffic without manual setup.
When you want to deploy a container quickly from your local machine or CI/CD pipeline.
When you want to pay only for the exact time your container is handling requests.
When you want to focus on writing code and not worry about server maintenance or patching.
Commands
This command deploys a container image to Cloud Run as a managed service in the us-central1 region and allows public access.
Terminal
gcloud run deploy example-service --image=gcr.io/cloudrun/hello --region=us-central1 --platform=managed --allow-unauthenticated
Expected OutputExpected
Deploying container to Cloud Run service [example-service] in project [your-project-id] region [us-central1] ✔ Deploying new service... Done. ✔ Creating Revision... ✔ Routing traffic... ✔ Setting IAM Policy... Service [example-service] revision [example-service-00001-abc] has been deployed and is serving 100 percent of traffic. Service URL: https://example-service-abcde.a.run.app
--image - Specifies the container image to deploy.
--platform - Specifies Cloud Run managed platform.
--allow-unauthenticated - Allows public access to the service.
Lists all Cloud Run services deployed in the us-central1 region to verify the deployment.
Terminal
gcloud run services list --platform=managed --region=us-central1
Expected OutputExpected
SERVICE REGION URL example-service us-central1 https://example-service-abcde.a.run.app
--platform - Specifies Cloud Run managed platform.
--region - Specifies the region to list services from.
Sends a request to the deployed Cloud Run service URL to check if the container is running and responding.
Terminal
curl https://example-service-abcde.a.run.app
Expected OutputExpected
Hello World!
Key Concept

If you remember nothing else from this pattern, remember: Cloud Run lets you run containers easily without managing servers, and it automatically scales your app with traffic.

Common Mistakes
Not specifying the --platform=managed flag when deploying.
Cloud Run defaults to different platforms; missing this flag can deploy to the wrong environment or fail.
Always include --platform=managed to deploy to the fully managed Cloud Run service.
Forgetting to allow unauthenticated access with --allow-unauthenticated.
Without this flag, the service is private and cannot be accessed publicly, causing connection errors.
Add --allow-unauthenticated if you want your service to be publicly accessible.
Using a container image that is not accessible or does not exist.
Cloud Run cannot deploy if the image URL is wrong or the image is private without proper permissions.
Use a valid, publicly accessible container image or configure permissions correctly.
Summary
Use 'gcloud run deploy' to deploy your container image to Cloud Run with automatic scaling.
Verify your service with 'gcloud run services list' to see deployed services and URLs.
Test your running container by sending a request to the service URL with curl.