Last active
May 15, 2019 04:32
-
-
Save yusufsyaifudin/8bb31a0b8da47b700f85bfdb76781c43 to your computer and use it in GitHub Desktop.
Cleaning up docker to reclaim disk space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# based on https://lebkowski.name/docker-volumes/ | |
# remove exited containers: | |
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v | |
docker volume ls -qf dangling=true | xargs -r docker volume rm | |
# remove unused images: | |
docker images --no-trunc | grep '<none>' | 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