Deploy Containers to Cloud Run
Beginner10 minTrending
Build and deploy a containerized application to Cloud Run with automatic HTTPS, scaling, and custom domain support.
Prerequisites
- -gcloud CLI installed
- -GCP project created
- -Docker image or source code
Steps
1
Authenticate and set the project
Signs in to GCP and selects the target project.
$ gcloud auth login && gcloud config set project my-project-id
2
Enable required APIs
Enables the Cloud Run and Artifact Registry APIs if not already active.
$ gcloud services enable run.googleapis.com artifactregistry.googleapis.com
3
Deploy from source code
Builds the container using Cloud Build, pushes to Artifact Registry, and deploys to Cloud Run in one command.
$ gcloud run deploy myservice --source . --region us-central1 --allow-unauthenticated
If you already have an image, use --image instead of --source.
4
Set environment variables
Configures environment variables for the running service.
$ gcloud run services update myservice --region us-central1 --set-env-vars "DB_HOST=10.0.0.1,NODE_ENV=production"
5
View service URL and status
Retrieves the auto-provisioned HTTPS URL for the service.
$ gcloud run services describe myservice --region us-central1 --format "value(status.url)"
Full Script
FAQ
Discussion
Loading comments...