Deleting unused images from Google Cloud Container Registry

Daan Geurts
Jun 20 · 1 min read

Google Cloud Platform is a great platform for hosting our clients application. We make use of Docker for our containers and Kubernetes for managing these containers.

We always have two GCP projects for a client application. One production and one development project. After each commit and push to Bitbucket we run a CircleCI workflow and pushing the created images to Google Cloud Container Registry. The development branch get pushed to the development project and the master branch get pushed to the production project.

The Container Registry stores the images in buckets and the amount of GB used is what you are charged for. So after 200 commits we have a lot of GB stored in that bucket and for that we are being charged. Especially the development project get filled up quickly.

Empty your bucket

Manually deleting these images is cumbersome work. So I’ve created a shell script to delete the old untagged and tagged images and leave a given number of images in tact.

My script is based on this neat little script:

You can find my script here:

I’m happy to receive feedback and improvements on the script.