Skip to content

Instantly share code, notes, and snippets.

@suhlig
Forked from mlebkowski/cleanup-docker.sh
Last active September 29, 2019 10:46
Show Gist options
  • Save suhlig/470d704ebb85d198ba14b4eb7b6764a9 to your computer and use it in GitHub Desktop.
Save suhlig/470d704ebb85d198ba14b4eb7b6764a9 to your computer and use it in GitHub Desktop.
Cleanup docker disk space https://lebkowski.name/docker-volumes/
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# This is an updated version of https://lebkowski.name/docker-volumes
main() {
remove-exited-containers
remove-unused-images
remove-unused-volumes
}
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 '<none>' | awk '{ print $3 }' | xargs -r docker rmi
}
remove-unused-volumes() {
docker volume ls -qf dangling=true | xargs -r docker volume rm
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment