Show Images Ordered by Size
docker image ls --format '{{.Size}}\t{{.ID}}\t{{.Repository}}:{{.Tag}}' \
| sort -t $'\t' -k1,1h
Purge Old Images
PURGE_REPO="hub.docker.io"
docker image ls --format '{{.Size}}\t{{.ID}}\t{{.Repository}}:{{.Tag}}' \
| grep -E $'\t'"${PURGE_REPO}/" \
| grep -E ':latest$' \
| sort -t $'\t' -k1,1h \
| while IFS=$'\t' read size id name; do
echo "=== ${name} ===";
docker image ls "${name%:*}" --format '{{.Size}}\t{{.ID}}\t{{.Repository}}:{{.Tag}}' \
| grep -v "${id}" \
| sort -t $'\t' -k1,1h \
| awk '{print $3}' \
| xargs -rt docker image rm;
done