Google cloud CLI cheatsheet

Basic google cloud CLI commands

view on github

Google cloud platform CLI commands

Table of contents

  1. Compute engine
  2. Artifact registry

Compute engine

List disk images available for instance provisioning

# list images
gcloud compute images list
# list images uri's
gcloud compute images list --uri

Start, stop and delete compute engine instances

# autocompletion is available
gcloud compute instances start "$instance"
gcloud compute instances stop "$instance"
gcloud compute instances delete "$instance"

List all external addresses for an instance

gcloud compute addresses list --filter="name=$instance"

Get current region

# it has to be current project's region
gcloud config get-value compute/region

Artifact registry

List locations hosting registries

gcloud artifacts locations list

Authenticate docker daemon to the registry hosted at $region

# DO NOT EXPOSE THE SERVICE ACCOUNT KEY
cat /path/to/gcloud.service.account.key.json | docker login -u _json_key --password-stdin "https://$region-docker.pkg.dev"

Manage images

# tag image for push to private gcloud registry
docker tag "$image:$tag" "$region-docker.pkg.dev/$project_id/$registry_name/$image:$tag"

# push image to the registry
docker push "$region-docker.pkg.dev/$project_id/$registry_name/$image:$tag"

# pull image (docker daemon has to be authenticated)
docker pull "$region-docker.pkg.dev/$project_id/$registry_name/$image:$tag"