Skip to content

Instantly share code, notes, and snippets.

@dbeley
Created March 12, 2021 11:23
Show Gist options
  • Save dbeley/d1227715b38597485e80f59db87929a1 to your computer and use it in GitHub Desktop.
Save dbeley/d1227715b38597485e80f59db87929a1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# docker prune
docker system prune -a
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)'
) | xargs -r rm -fr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment