Created
November 9, 2018 20:51
-
-
Save mikeslattery/b16a101e1000d626d770cbe99952cce5 to your computer and use it in GitHub Desktop.
This file contains 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
docker system df | |
df -h | |
# Delete builds and workspaces more 6+ months old | |
find /var/lib/jenkins/jobs -maxdepth 6 -mtime +180 -name build.xml -print0 | xargs -0 -I{} dirname {} | xargs -d '\n' -r rm -rf | |
find /var/lib/jenkins/jobs -maxdepth 3 -mtime +180 -name workspace -print0 | xargs -0 -r rm -rf | |
# Stop containers running more than 2 days, except Jenkins | |
docker ps | grep -E 'days|weeks|months' | grep -Ev "$(hostname)|CONTAINER" | awk '{ print $1; }' | xargs -r docker stop | |
# Remove stopped containers | |
docker ps -aq --no-trunc -f status=exited | xargs -r docker rm | |
# Remove all compose networks | |
docker network ls -f driver=bridge | grep -v 'bridge.*bridge' | grep -v NETWORK | awk '{ print $1; }' | xargs -r docker network rm || true | |
# Remove images created or pulled more than 7 days ago. | |
# Steps: Danglers. Get full image IDs. Convert to file names. Filter on age. Convert back to IDs. Delete. | |
docker images -q -f dangling=true | xargs -r docker rmi || true | |
docker images --format '{{.ID}}' | sort | uniq | xargs -r docker inspect -f '{{.Id}}' | \ | |
ssh -tt gnl0034 sudo sed -r 's|^sha256:|/var/lib/docker/image/overlay2/imagedb/content/sha256/|;' | \ | |
xargs -I{} sudo find {} -mtime +7 -type f | \ | |
sed 's|^.*/||;' | \ | |
xargs -r docker rmi -f || true | |
# Dangling volumes and images (again) | |
docker images -q -f dangling=true | xargs -r docker rmi || true | |
docker volume ls -qf dangling=true | xargs -r docker volume rm || true | |
docker system df | |
df -h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment