Docker Cleanup Scripts Comparison

Docker Cleanup Scripts Comparison

If you've used Docker for any length of time you most likely have left a trail of unused (dangling) Docker images and containers in your dust. Abandoned images and containers are not necessarily a bad thing but starts becoming more of a housekeeping/administrative tasks to purge items which are not in use.

Before we get started I have to throw a disclaimer as these scripts will delete images and containers and possibly running containers. Be sure to test these scripts before running in production and that your Docker installation meets their requirements

I cherry picked GitHub for the scripts with the most amount of GitHub Stars. Since we are deleting things I want a vote of confidence from the community. I selected scripts with a high number of stars. It is also important to point that I highlighter which scripts contain a dry run option because we want to make sure we have the right flags set before nuking your containers.

Docker Cleanup Scripts

Spotify Docker Garbage Collection (1,320 GitHub Stars) - The Spotify team released this utility a little over 2 years ago. This a production tried and tested script used by a lot of Docker users. A unique feature of this script is you can run it either as a container or as a cron job on the Docker Host.

Script has a Dry Run Option

Docker-Clean (204 GitHub Stars) - This script actually made it to the front page of HN not so long ago which is quite impressive alone. I sent a feature request to add network cleanup option and it was implemented before I could finish my coffee. This is a great all-rounder script!

Script has a Dry Run Option

Tutum Cloud Cleanup (70 GitHub Stars) - This is a very basic script which only removes images. It has three options: Time between cleans, how long to wait before a image is marked stale, and exclusion list.

No Dry Run Flag available

Docker Cleanup Volumes (817 GitHub Stars) - Does exactly as advertised and handles volumes only. This will nuke any orphaned volume still dangling around.

Script has a Dry Run Option

Docker-Cleanup (160 GitHub Stars) - This script is a combination of the Tutum Cleanup and Docker Cleanup volumes scripts. The script uses Environment variables instead of flags which is handy to change settings since this runs in a container.

Script has a Dry Run Option

Conclusion

I used the Spotify Garbage collection script for awhile before finding the docker-clean script. The Docker-Clean script checks all the boxes for me. The only thing that you may need is something to manage cleaning volumes which Docker Cleanup Volumes handles.

But before you try anything be sure to run these script in a test environment with non-production data. You've been warned.

Happy cleaning.

Follow me

If you liked this article be sure to Follow Me on Twitter to stay updated!