Created
March 2, 2018 21:03
-
-
Save ishneetdua/76a87d833c7adfe686394b0f32f6f5e2 to your computer and use it in GitHub Desktop.
Docker cleanup
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
#!/bin/sh | |
docker ps -a -q | while read cid | |
do | |
fini=$(docker inspect $cid | grep FinishedAt | awk -F\" '{printf("%.19s", $4)}') | |
diff=$(expr $(date +"%s") - $(date --date="$fini" +"%s")) | |
echo $diff | |
if [ $diff -gt 86400 ] | |
then | |
docker rm $cid | |
fi | |
done | |
docker rmi $(docker images -a) | |
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