Google Cloud provides hosted services for running applications. Projects group services together, connect to billing accounts, and require explicit service enablement before use. section 14.4
For container workloads, Cloud Run uses images stored in Artifact Registry. The practical workflow is to create a project and registry, authenticate Docker, push an image, then deploy and inspect the workload with gcloud. section 14.4
A typical setup follows these steps:
- Initialize gcloud, create a uniquely named project, link billing, and enable Artifact Registry. section 14.4
- Create a Docker repository, configure Docker authentication, retag the source image, and push it to Artifact Registry. section 14.4
- Enable Cloud Run and deploy either a job or a web service; execute jobs and read logs, or browse a service URL. section 14.4
# initialize your CLI (if you haven't already): gcloud init # store variables - you will need a unique project name, # and any region will do; with PowerShell: $REGION='us-east1' $PROJECT='<your-project-name>' # OR Linux shell: REGION='us-east1' PROJECT='<your-project-name>' # create the project: gcloud projects create $PROJECT # list your billing accounts: gcloud billing accounts list # link your new project to the billing account: gcloud billing projects link $PROJECT ` --billing-account=<your-billing-account-id> # and now enable the Artifact Registry service: gcloud services enable artifactregistry.googleapis.com ` --project=$PROJECT
Use the command listing to create and configure a Google Cloud project from the command line. section 14.4
# create the registry in your project:
gcloud artifacts repositories create ch14 `
--repository-format=docker --project=$PROJECT --location=$REGION
# print the information - this includes the registry domain:
gcloud artifacts repositories describe ch14 `
--project=$PROJECT --location=$REGION
# store the domain in a variable - PowerShell:
$REGISTRY="${REGION}-docker.pkg.dev"
# OR Linux shell:
REGISTRY="${REGION}-docker.pkg.dev"
# authenticate the registry with the Docker CLI:
gcloud auth configure-docker --quiet $REGISTRY
# pull the source image:
docker pull ghcr.io/diamol2e/ch14-hello-cloud
# tag it with your Artifact Registry reference:
docker tag ghcr.io/diamol2e/ch14-hello-cloud `
"$REGISTRY/$PROJECT/ch14/hello-cloud"
# and push:
docker push "$REGISTRY/$PROJECT/ch14/hello-cloud"
Use the listing to create Artifact Registry, authenticate Docker, retag an image, and push it. section 14.4
# enable the service: gcloud services enable run.googleapis.com --project=$PROJECT # deploy the job using the registry image: gcloud run jobs deploy hello-cloud ` --image="$REGISTRY/$PROJECT/ch14/hello-cloud" --project=$PROJECT ` --region=$REGION # now execute the job - this starts the container: gcloud run jobs execute hello-cloud --project=$PROJECT ` --region=$REGION # and print the logs: gcloud run jobs logs read hello-cloud --project=$PROJECT ` --region=$REGION
Use the listing to deploy, execute, and inspect a Cloud Run job. section 14.4
# pull the source image: docker pull ghcr.io/diamol2e/ch14-pi-web # tag it with your Artifact Registry reference: docker tag ghcr.io/diamol2e/ch14-pi-web "$REGISTRY/$PROJECT/ch14/pi-web" # and push: docker push "$REGISTRY/$PROJECT/ch14/pi-web" # now deploy the service: gcloud run deploy pi-web --image="$REGISTRY/$PROJECT/ch14/pi-web" ` --port=80 --allow-unauthenticated --project=$PROJECT --region=$REGION # print the details: gcloud run services describe pi-web --project=$PROJECT --region=$REGION # browse to the service URL to test the app
Use the listing to deploy a web container with Cloud Run and test its service URL. section 14.4

