August 1, 2016

docker-cleanup to garbage collect old images

Filed under: Technical — Tags: , , , — James Bunton @ 12:00 am

Docker is a very useful containerisation platform. I use it so much that I regularly fill up /var/lib/docker with old images and get out of disk space errors. Unfortunately Docker has no automatic garbage collection mechanism to clean up unused images. I wrote a simple shell script which I run from time to time.

It’s a bit of a hack, but I’ve found it very useful. Here it stands in all its non-glory! :)

#!/bin/bash

docker rm -f $(docker ps -a -q)
docker rmi $(docker images -q --filter "dangling=true")
docker volume rm $(docker volume ls -q)

Leave a Reply

Your email address will not be published. Required fields are marked *