Reputation: 20130
All
use Google Computing Engine to run Monte Carlo by deploying Docker images, running them, deleting them, deploying more images, ...
If I look into disk usage of the bucket which has containers/images
gsutils du gs://bucket
I'll get close to 6Gb of space used
But! I know that right now there is only one docker image
gcloud container images list --repository=repo
and it should take no more than 1.5Gb.
Is there good and simple way to do garbage collection? How I could clean-up all images which are NOT used right now, and get storage usage down to something real?
Upvotes: 0
Views: 2377
Reputation: 11
If it helps, here is little bash script which removes all matching images built before a given date: https://gist.github.com/27Bslash6/ba9dca6ca6b90c05d6bfa9136c667e9a
For example, to delete all gcr.io/things/stuff images older than 1st July 2017:
./gcrgc.sh gcr.io/things/stuff 2017-07-01
Includes an option to perform a trial run, listing images which would be deleted.
Upvotes: 1
Reputation: 392
You can use the Cloud Console to delete some images that might have some unused tags.
You can also use the gcloud commands to list and delete them, here an example of the commands to be run:
gcloud container images list-tags gcr.io/project-id/hello-node
DIGEST TAGS TIMESTAMP
e302a6a81293 v1 2015-01-26T15:29:27
dac925b4030f latest 2017-12-10T15:33:41
Untag your unused versions
gcloud container images untag gcr.io/project-id/hello-node:v1
List your images again
gcloud container images list-tags gcr.io/project-id/hello-node
DIGEST TAGS TIMESTAMP
e302a6a81293 2015-01-26T15:29:27
dac925b4030f latest 2017-12-10T15:33:41
Delete your untag image, you need to use the following format for digest: gcr.io/repository@sha256:digest
gcloud container images delete gcr.io/project-id/hello-node@sha256:e302a6a81293
So listing your images should give you now:
DIGEST TAGS TIMESTAMP
dac925b4030f latest 2017-12-10T15:33:41
More info about the 'gcloud container images delete' in here. You can also delete the image and the tag at the same time using flag '--force-delete-tags':
gcloud container images delete gcr.io/project-id/hello-node@sha256:dac925b4030f --force-delete-tags
Upvotes: 1