diff --git a/docker-clean b/docker-clean index 3870522..d6be3e4 100755 --- a/docker-clean +++ b/docker-clean @@ -11,20 +11,5 @@ step "Removing containers created / exited >= ~1h ago..." CONTAINERS=$(docker ps -a | gawk '/(hours?|days?|weeks?|months?) ago\s+(Created|Exited)/{ print $1 }' | xargs) [ -n "${CONTAINERS}" ] && docker rm ${CONTAINERS} -step "Untagging all images not used by containers..." -PS_OUTPUT=$(docker ps -a) -for img in $(docker images | gawk '/^[a-z].*(hours?|days?|weeks?|months?) ago/{ print $1":"$2 }' | grep -v '' | sort | uniq); do - imghash=$(docker inspect "${img}" | jq -r '.[0].Id' | sed -E 's/^sha256:(.{12}).*/\1/') - - # Check if image is currently active - (echo "${PS_OUTPUT}" | grep -q "\s${img}\s") && continue - # Check if image with stripped ":latest" is currently active - (echo "${PS_OUTPUT}" | grep -q "\s${img%:latest}\s") && continue - # Check if image hash is currently active (sometimes docker looses named references) - (echo "${PS_OUTPUT}" | grep -q "\s${imghash}\s") && continue - - docker rmi --no-prune "${img}" -done - -step "Removing dangling images..." -docker image prune -f +step "Removing unused and dangling images..." +docker image prune -a -f