Skip to content

Instantly share code, notes, and snippets.

@mauricioprado00
Created October 13, 2016 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioprado00/bc3869f7c9397af3437cbd0b1b8f9be4 to your computer and use it in GitHub Desktop.
Save mauricioprado00/bc3869f7c9397af3437cbd0b1b8f9be4 to your computer and use it in GitHub Desktop.
docker build cleanup
#!/usr/bin/env bash
# see https://lebkowski.name/docker-volumes/
# The command doesn’t remove anything, but simply passing the results to xargs -r rm -fr does so.
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
docker ps -aq | xargs docker inspect | jq -r '.[]|.Mounts|.[]|.Name|select(.)'
)
# Hint: docker 1.9 has new volume management system, so it’s way easier with this version:
# docker volume ls -qf dangling=true | xargs -r docker volume rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment