Each time I build an image with docker, it gets tagged with the project identifier. You know, Something like ‘$ docker build -t cfreeman/reprage .’ The problem is that old images don’t get cleaned up, they just get left behind. Dangling until I clean them up, usually when I hit an inevitable ‘no space left on device’ error when building something.

The script uses grep to filter output from docker to return only the images without a tag. Bash builtins (‘while’ and ‘read’) are used to read one line at a time from the filtered output. These lines get broken into words and sequentially assigned to an array. The docker image ID lives at index ‘2’ of this array, the ID is used to remove the image from docker.

EDITS:

2017/03/07 - Added ability to remove dangling volumes.

Hi! Subconsciously you already know this, but let's make it obvious. Hopefully this article was helpful. You might also find yourself following a link to Amazon, Lego or eBay to learn more about parts or equipment. If you end up placing an order, I make a couple of dollarydoos. We aren't talking a rapper lifestyle of supercars and yachts, but it does help pay for the stuff you see here. So a massive shoutout to everyone that enables this place. Thanks!