Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a tag to an image in google cloud container registry without installing docker locally?

I need to add a tag on an image on a repo in Google Container Registry, and I was wondering whether this could be done without having to install docker locally and doing pull, tag, push on the image. I know how to do so using the UI, but I wanted to automate this process.

Thanks.

like image 782
Vitorqb Avatar asked Aug 31 '25 18:08

Vitorqb


2 Answers

If you are looking for a Google Container Registry specific solution, you can use the gcloud container images add-tag command. For example:

gcloud container images add-tag gcr.io/myproject/myimage:mytag1 \ gcr.io/myproject/myimage:mytag2

Reference: https://cloud.google.com/sdk/gcloud/reference/container/images/add-tag

If you want to use code, I'd suggest taking a look at those libraries

  • Go: https://github.com/google/go-containerregistry
  • Python: https://github.com/google/containerregistry
like image 183
Philippe Deslauriers Avatar answered Sep 03 '25 14:09

Philippe Deslauriers


If you don't want to use Docker you have the option to use the gcloud command line, you need just to configured Docker to use gcloud as a credential helper:

gcloud auth configure-docker

After that you can List images by their storage location:

gcloud container images list --repository=[HOSTNAME]/[PROJECT-ID]

Or List the versions of an image

gcloud container images list-tags [HOSTNAME]/[PROJECT-ID]/[IMAGE]

And you can as well Tag images

gcloud container images add-tag \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]:[TAG] \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]:[NEW_TAG]

or

gcloud container images add-tag \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]@[IMAGE_DIGEST] \
[HOSTNAME]/[PROJECT-ID]/[IMAGE]:[NEW_TAG]

All the described above can be done trough the UI as well.

For your question "I wanted to automate this process" not sure what are you looking for but you can create a bash script including the gcloud command and run it from you cloud shell

like image 31
Alioua Avatar answered Sep 03 '25 12:09

Alioua