0
0
GCPcloud~5 mins

Cloud Run for containerized services in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
Running apps in containers can be tricky because you need servers and setup. Cloud Run lets you run container apps easily without managing servers. It automatically handles scaling and availability for you.
When you want to run a web app without managing servers or infrastructure.
When you have a containerized app and want it to scale automatically based on traffic.
When you want to deploy a microservice quickly with minimal setup.
When you want to pay only for the time your app is handling requests.
When you want to run stateless apps that respond to HTTP requests.
Commands
This command deploys a container image to Cloud Run as a new service named 'example-service'. It uses the managed platform in the us-central1 region and allows public access.
Terminal
gcloud run deploy example-service --image gcr.io/cloudrun/hello --platform managed --region us-central1 --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-abc123uc.a.run.app
--image - Specifies the container image to deploy.
--platform - Chooses the Cloud Run platform; 'managed' means fully managed by Google.
--allow-unauthenticated - Allows public access to the service without login.
Lists all Cloud Run services in the specified 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-abc123uc.a.run.app
--platform - Specifies the Cloud Run platform.
--region - Specifies the region to list services from.
Sends an HTTP request to the deployed Cloud Run service URL to check if it responds correctly.
Terminal
curl https://example-service-abc123uc.a.run.app
Expected OutputExpected
Hello World!
Key Concept

If you remember nothing else from this pattern, remember: Cloud Run lets you run container apps without managing servers, automatically scaling them based on traffic.

Common Mistakes
Not specifying the --platform managed flag during deployment.
Cloud Run supports multiple platforms; without this flag, deployment may fail or go to the wrong platform.
Always include --platform managed to deploy to the fully managed Cloud Run service.
Forgetting to add --allow-unauthenticated when you want public access.
Without this flag, the service requires authentication and won't be accessible publicly.
Add --allow-unauthenticated to allow anyone to access the service.
Using a container image that does not listen on the correct port or handle HTTP requests.
Cloud Run expects the container to respond to HTTP requests on port 8080 by default.
Ensure your container app listens on port 8080 and handles HTTP requests properly.
Summary
Deploy a container image to Cloud Run using gcloud with the deploy command.
List deployed services to verify the deployment and get the service URL.
Test the deployed service by sending an HTTP request to its URL.