Automated cleanup of Docker leavings

As much as I like Docker, one thing it doesn't do well: cleanup whatever is left on my hard drive after running it for a while. There're generally two kinds of Docker Waste:

So, here's the script. Just put it in your /etc/cron.daily directory and live quite happily ever after:

#!/bin/bash
docker ps -a -q --filter="status=created" | xargs --no-run-if-empty \
docker rm
docker ps -a -q --filter="status=exited" | xargs --no-run-if-empty \
docker rm
docker images -q -f dangling=true | xargs --no-run-if-empty \
docker rmi

#MostlyUnixish #docker