When we push repeatedly into gcr.io
with the same image name and a version (tag), there is a high number of untagged images.
Is there a simple way to remove all untagged images from a project, or at least for a single image, to avoid incurring Storage costs?
Go to the Container Registry page. Click on the image name to see version(s) of that image. In the registry, check the box next to the version(s) of the image that you want to delete. Click DELETE on the top of the page.
Container images stored in the same project as the one you are creating the job or service in. Container images from other Google Cloud projects (provided that the correct IAM permissions are set).
gcloud container images list-tags gcr.io/project-id/repository --format=json --limit=unlimited
will give you an easily consumable json blob of info for images in a repo (such as digests w/ associated tags).
In order to just enumerate all digests which lack tags:
gcloud container images list-tags gcr.io/project-id/repository --filter='-tags:*' --format='get(digest)' --limit=unlimited
Which you can iterate over and delete with:
gcloud container images delete --quiet gcr.io/project-id/repository@DIGEST
Handy when you glue them together with awk and xargs
gcloud container images list-tags gcr.io/${PROJECT_ID}/${IMAGE} --filter='-tags:*' --format='get(digest)' --limit=unlimited | awk '{print "gcr.io/${PROJECT_ID}/${IMAGE}@" $1}' | xargs gcloud container images delete --quiet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With