Google cloud CLI cheatsheet

Basic google cloud CLI commands

view on github

Google 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 instance

gcloud compute addresses list --filter="name=<instance>"

✔️ get region

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

Google artifact registry

✔️ List locations hosting registries

gcloud artifacts locations list

✔️ Authenticate the docker daemon to the google cloud docker registry hosted at <location>

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

✔️ Use the google cloud docker registry to 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>