Skip to content

Instantly share code, notes, and snippets.

@illoyd
Created July 20, 2026 03:02
Show Gist options
  • Select an option

  • Save illoyd/195174e1b007016d33e0c65e5b9b852a to your computer and use it in GitHub Desktop.

Select an option

Save illoyd/195174e1b007016d33e0c65e5b9b852a to your computer and use it in GitHub Desktop.
Docker Prune Preview
# Add to your own config at ~/.config/mise/config.toml
[tasks."docker:prune-preview"]
description = "Dry-run of docker system prune: show what each prune flavour WOULD remove"
run = '''
{% raw %}
hr() { printf '\n\033[1m== %s\033[0m\n' "$1"; }
hr "STOPPED CONTAINERS (removed by: docker container/system prune)"
docker ps -a --filter status=exited --filter status=created \
--format 'table {{.Names}}\t{{.Status}}\t{{.Image}}\t{{.Size}}'
hr "DANGLING IMAGES (removed by: docker image/system prune)"
docker images -f dangling=true
hr "IMAGES NOT USED BY ANY CONTAINER (additionally removed by: prune -a)"
USED=$(docker ps -aq | xargs -r docker inspect --format '{{.Image}}' | sort -u)
docker images --no-trunc --format '{{.ID}}\t{{.Repository}}:{{.Tag}}\t{{.Size}}' | \
while IFS="$(printf '\t')" read -r id ref size; do
case "$USED" in
*"$id"*) ;;
*) printf '%s\t%s\n' "$ref" "$size" ;;
esac
done | column -t
hr "DANGLING VOLUMES (removed by: prune --volumes — DATA LOSS territory)"
docker volume ls -f dangling=true
hr "BUILD CACHE (removed by: builder/system prune)"
docker builder du 2>/dev/null | tail -3
hr "RECLAIMABLE SUMMARY (docker system df)"
docker system df
{% endraw %}
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment