summaryrefslogtreecommitdiff
path: root/tcwg-cleanup-stale-containers.sh
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2016-11-17 06:26:00 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2016-11-17 06:26:00 +0000
commit2a59944f6c87184b6af0729c5115e374d62e9817 (patch)
tree55cf9b2aa93353265a1f55cb31747db19f82cca3 /tcwg-cleanup-stale-containers.sh
parentd027afcf4a0415b8b2868c5429745b3418a525c7 (diff)
tcwg-cleanup-stale-containers: Reword removal of unused images
... to avoid spurious warning from removing untagged images that are used by non-running containers. Change-Id: I6d8f665c2c1559cd7826236cbfac16cbc48e1f31
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-xtcwg-cleanup-stale-containers.sh19
1 files changed, 14 insertions, 5 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh
index 97fd3f9c..d69c8c1d 100755
--- a/tcwg-cleanup-stale-containers.sh
+++ b/tcwg-cleanup-stale-containers.sh
@@ -75,13 +75,22 @@ if [ x"$(docker volume ls -q -f dangling=true)" != x"" ]; then
fi
fi
-if [ x"$(docker images -q -f dangling=true)" != x"" ]; then
- echo "Removing untagged images"
- echo "Increasing exit code by 4 to indicate untagged images"
+rm_images=()
+for image in $(docker images -q -f dangling=true); do
+ if ! docker ps -a --format "{{.Image}}" | grep -q $image; then
+ rm_images=("${rm_images[@]}" $image)
+ fi
+done
+
+if [ ${#rm_images[@]} != 0 ]; then
+ echo "Removing unused images"
+ echo "Increasing exit code by 4 to indicate unused images"
status="$(($status+4))"
if ! $dry_run; then
- docker images -q -f dangling=true | xargs -i@ docker rmi @ | cat
- echo "xargs docker rmi exit status: ${PIPESTATUS[3]}"
+ for image in "${rm_images[@]}"; do
+ docker rmi $image | cat
+ echo "docker rmi exit status: ${PIPESTATUS[0]}"
+ done
else
echo "DRY_RUN: NOT REMOVING UNTAGGED IMAGES"
fi