Skip to content

Instantly share code, notes, and snippets.

@hedzr
Created July 10, 2020 14:16
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hedzr/1d3e2de5eee40bccad19ad6392a1a820 to your computer and use it in GitHub Desktop.
function docker-rmi-none() {
for i in `docker-images-none-cids`; do
echo $i
#local cid=$(docker-cid "$i")
#[ "$cid" != "" ] &&
local pid=$(docker-pid "$i" 2>/dev/null)
[ "$pid" != "" ] && echo "-------- Cleaning the stopped container: $i, $pid" && docker rm -f $pid
[ "$i" != "" ] && echo "-------- Erasing the container: $i, $pid" && docker rmi -f $i
done
}
function docker-images-none-cids() {
docker images | grep -Ei "<none>" | grep -Eio " ([0-9a-f]{12}) "
}
function docker-cid() {
CID=$(docker ps | grep -Eoi "^[0-9a-f]+[ \t]+$1" | grep -Eoi "^[0-9a-f]+")
[ "$CID" != "" ] && echo $CID || echo $1
}
alias docker-pid="docker inspect --format ''"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment