Skip to content

Instantly share code, notes, and snippets.

@xiongtx
Created August 30, 2017 17:58
Show Gist options
  • Save xiongtx/fbf915d420e0305d43372a0723ae0c5c to your computer and use it in GitHub Desktop.
Save xiongtx/fbf915d420e0305d43372a0723ae0c5c to your computer and use it in GitHub Desktop.
Docker-related stuff
function rm-old-images() {
IMAGESINFO=$(sudo docker images --no-trunc --format '{{.ID}} {{.Repository}} {{.Tag}} {{.CreatedSince}}' |grep -E " (weeks|months|years)")
TAGS=$(echo "$IMAGESINFO" | awk '{ print $2 ":" $3 }' )
IDS=$(echo "$IMAGESINFO" | awk '{ print $1 }' )
for t in $TAGS; do sudo docker rmi $t; done
for i in $IDS; do sudo docker rmi $i; done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment