Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ishneetdua/76a87d833c7adfe686394b0f32f6f5e2 to your computer and use it in GitHub Desktop.
Save ishneetdua/76a87d833c7adfe686394b0f32f6f5e2 to your computer and use it in GitHub Desktop.
Docker cleanup
#!/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