This chapter follows IAM in Google Cloud. Artifact Registry is Google Cloud’s managed registry for OCI container images, language packages, and related formats. Google Container Registry is retired; new work uses Artifact Registry only.
The series deployer service account needs roles/artifactregistry.writer before you can push.
Repositories and formats
Create a repository in a location (region) with a format:
| Format | Typical use |
|---|---|
| Docker | Cloud Run, GKE, Cloud Build images |
| npm, Maven, Python, … | Language packages for builds |
Docker image URLs follow:
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAGExample: europe-west1-docker.pkg.dev/my-project/file-api/app:v1.
Create a Docker repository
gcloud artifacts repositories create file-api \ --repository-format=docker \ --location=europe-west1 \ --description="Series file API images"List repositories:
gcloud artifacts repositories list --location=europe-west1Grant readers if other projects or people must pull without write access:
gcloud artifacts repositories add-iam-policy-binding file-api \ --location=europe-west1 \ --member="serviceAccount:file-api-runtime@YOUR_PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/artifactregistry.reader"Cloud Run’s service agent pulls images at deploy time; project defaults usually suffice, but explicit reader on the repository documents intent.
Authenticate Docker to Artifact Registry
Configure the Docker credential helper:
gcloud auth configure-docker europe-west1-docker.pkg.devOn CI, run as the deployer service account (ADC or impersonation) before docker push.
Build and tag locally from the series app directory:
export REGION=europe-west1export PROJECT_ID=YOUR_PROJECT_IDexport IMAGE="${REGION}-docker.pkg.dev/${PROJECT_ID}/file-api/app:v1"
docker build -t "${IMAGE}" .docker push "${IMAGE}"Verify:
gcloud artifacts docker images list \ "${REGION}-docker.pkg.dev/${PROJECT_ID}/file-api" \ --include-tagsTags, immutability, and cleanup
Use immutable tags on production repositories if your org requires it—overwriting :latest cannot happen accidentally.
Cleanup policies delete old untagged manifests or aged images to control cost:
gcloud artifacts repositories set-cleanup-policies file-api \ --location=europe-west1 \ --policy=keep-recent.jsonA minimal policy file keeps the last few versions; adjust for compliance needs.
Vulnerability scanning
Artifact Registry can scan images for known CVEs (configuration depends on organization policy). View results in the Console or with:
gcloud artifacts docker images scan "${IMAGE}"Treat critical findings like application defects: rebuild base images, pin patched tags, and redeploy Cloud Run.
IAM on repositories
Prefer repository-level roles/artifactregistry.reader and roles/artifactregistry.writer over project-wide storage roles. The deployer account is a writer; runtime and Cloud Run need read access to pull.
Next: Deploying containers with Cloud Run runs this image as a managed service.
Check your understanding
Question 1 of 6
0 of 6 checked