Also search for image with stripped latest tag

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-02-20 22:40:55 +01:00
parent 0c1efb0e64
commit 7dafa5c0fc
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -14,7 +14,7 @@ CONTAINERS=$(docker ps -a | awk '/(hours?|days?|weeks?|months?) ago\s+(Created|E
step "Untagging all images not used by containers..."
PS_OUTPUT=$(docker ps -a)
for img in $(docker images | awk '/^[a-z].*(hours?|days?|weeks?|months?) ago/{ print $1":"$2 }' | grep -v '<none>' | sort | uniq); do
if ! ( echo "${PS_OUTPUT}" | grep -q "\s${img}\s" ); then
if ! ( echo "${PS_OUTPUT}" | grep -q "\s${img}\s" ) && ! ( echo "${PS_OUTPUT}" | grep -q "\s${img%:latest}\s" ); then
docker rmi --no-prune "${img}"
fi
done