Skip to content

Instantly share code, notes, and snippets.

@cheshirecode
Last active February 27, 2018 07:40
Show Gist options
  • Save cheshirecode/2c98ebd0c86ce83e5229e55c8c28afd7 to your computer and use it in GitHub Desktop.
Save cheshirecode/2c98ebd0c86ce83e5229e55c8c28afd7 to your computer and use it in GitHub Desktop.
Helper Docker functions
# remove docker images by tag, default is *none*. *blah* to remove those with tags similar to "blah"
function __dockerRemoveImageByTag__ {
param( [string]$tag = "*none*" )
docker images -a | ForEach-Object {
If($_ -like $tag) {
Write-Output $_
docker rmi -f $($_.Split('', [System.StringSplitOptions]::RemoveEmptyEntries)[2]) 2> $null
}
}
}
Set-Alias docker-remove-image-by-tag __dockerRemoveImageByTag__;
# clean-up docker images/containers/volumes etc in 1 command
function __dockerCleanup__ {
docker container prune -f;
docker image prune -f;
docker rmi $(docker images --quiet --filter "dangling=true");
docker volume prune -f ;
docker system prune -f;
}
Set-Alias docker-cleanup __dockerCleanup__;
#!/bin/bash
if [ "$1" == "-h" ]; then
echo "Usage: `basename $0` 1.0 would remove all images with 1.0 in name/tag"
exit 0
fi
docker images -a | grep $1 | awk '{print $3}' | xargs docker rmi
#!/bin/sh
docker images -a --no-trunc --format '{{.ID}} {{.CreatedSince}}' \
| grep ' months' | awk '{ print $1 }' \
| xargs --no-run-if-empty docker rmi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment