Artifact Registry provides a Google Cloud repository for container images used by Cloud Run. Before deploying, create a repository, authenticate Docker, retag the image with Google Cloud’s reference format, and push it. section 14.4
Use this workflow to prepare an image for Cloud Run:
- Create or select a Google Cloud project, connect billing, and enable the Artifact Registry service. section 14.4
- Create a Docker repository in a chosen region, then inspect it to obtain the registry domain. section 14.4
- Configure Docker authentication, pull the source image, retag it, and push the new reference. section 14.4
- Deploy the pushed image to a Cloud Run job or service and verify it by executing the job, reading logs, or opening the service URL. section 14.4
Image reference
An image pulled as ghcr.io/diamol2e/ch14-hello-cloud can be retagged as us-east1-docker.pkg.dev/diamol2ees/ch14/hello-cloud. The reference combines the regional registry domain, project, repository, and image name. 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"
Follow the runnable commands for creating a Docker repository, discovering its domain, authenticating Docker, and pushing an image. 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 setup commands to initialize gcloud, create a project, link billing, and enable Artifact Registry. section 14.4
