简体   繁体   中英

How to list the published container images in the Google Container Registry in a CLI in image size order

Using a CLI, I want to list the images in each repository in a Google Container Registry project but with the following conditions:

  • Lists the images with the latest tag only
  • Lists the human-readable size of the images
  • Lists the name of the images

The closest I've managed to get us through gsutil:

gsutil du -h gs://eu.artifacts.my-registry.appspot.com/containers/images

Resulting in:

33.77 MiB   gs://eu.artifacts.my-registry.appspot.com/containers/images/sha256:03c1a2387ef6cb30a7428a46821f946d6a2c591a26cb2066891c55b2b6846ae2
1.27 MiB    gs://eu.artifacts.my-registry.appspot.com/containers/images/sha256:03c1e7db6bf0140bd5fa34236a35453cb73cef01f6d89b98bc5995ae8ea07aaf
1.32 KiB    gs://eu.artifacts.my-registry.appspot.com/containers/images/sha256:03c3c97495d60c68d37d04a7e6c9b3a48bb159ce5dde13d0d81b4e75e2a3f1d4
81.92 KiB   gs://eu.artifacts.my-registry.appspot.com/containers/images/sha256:03c5483cb8ac9c9ae498507e15d68d909a11859a8e5238556b7188e0af4d9264
457.43 KiB  gs://eu.artifacts.my-registry.appspot.com/containers/images/sha256:03c7f98faa1cfc05264e743e23ca2e118d24c57bfd67d5cb2e2c7a57e8124b6c
7.88 KiB    gs://eu.artifacts.my-registry.appspot.com/containers/images/sha256:03c83b13d044844cd3f6b278382e408541f22029acaf55d9e7e5689b8d51eeea

But obviously this does not meet most of my criteria.

The information is available through the GUI like so on a per image basis:

谷歌控制台

Any ideas?

I'm open to gsutil, gcloud, docker, anything really which can be installed on a docker container.

You can use the Google Cloud UI to accomplish this. There's a column selector right next to the filter bar and it has an option for the image size.

Once the column is displayed, you'll be able to order by size.

Its seems you have only one outstanding issue with listing container images size after reading your comment at Jason 's answer. So it is not possible to retrieve with gcloud command directly. Here are two work around I tested:

  1. You can use gcloud container images describe command to see the size of the images. Make sure you use "--log-http" flag with it. Command should be like this:

$ gcloud container images describe gcr.io/myproject/myimage:tag --log-http

  1. Another way to get the size of the image is using gsutil stat command . So here's what I did:

a. Upon running below command, I listed all my images from the GCS bucket and saved it to a file called images.txt

$ gsutil ls "BUCKET URL" > images.txt

b.I ran gcloud stat command like below to read image names from the images.txt file and return size of the images chronologically.

$ for x in $(cat images.txt); do `gsutil stat $x | grep Content-Length | awk '{print $2}'`; done

You can customize this little script according to your need.

I understand these are not efficient workaround but thats all seems to be an option now. However, GCR just implements the docker container API, so may be you can read this document to see if you can find/do something of your own.

Hi here just to share a rudimental script which takes the first tag and get the size of the whole layers and write it on a report, it takes ages on 3TB repo but at least i know which repo is big.

 echo "REPO,SIZE" > repository-size-report.csv for REPO in $(gcloud container images list --repository eu.gcr.io/comerge-comerge01-171833 --format="table[no-heading](NAME)"); do for TAGS in $(gcloud container images list-tags $REPO --format="table[no-heading](TAGS)"); do TAG=$(echo $TAGS | cut -d, -f1) SUM=0 for SIZE in $(gcloud container images describe $REPO:$TAG --log-http 2>&1 | grep size | grep -o '[0-9][0-9]*'); do SUM=$((SUM + SIZE)) done HSUM=$(echo $SUM | numfmt --to iec --format "%8f") echo "$REPO:$TAG,$HSUM" echo "$REPO:$TAG,$HSUM" >> repository-size-report.csv done done

You can use the command gcloud container images list command to accomplish this task; however, you will need to set the appropriate flags to fulfill your use case. You can read more about the command and the flag options here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM