From e29a8862547ffac302c24e07f84a090b79931e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 1 Jun 2015 22:37:28 +0200 Subject: [PATCH] warn if only -lt half of the images are in use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- tests/6_docker_security_operations.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/6_docker_security_operations.sh b/tests/6_docker_security_operations.sh index 7cc1320..f5b1f01 100644 --- a/tests/6_docker_security_operations.sh +++ b/tests/6_docker_security_operations.sh @@ -37,6 +37,14 @@ set +f; unset IFS # 6.6 check_6_6="6.6 - Avoid image sprawl" images=$(docker images -q | wc -l | awk '{print $1}') +active_images=0 + +for c in $(docker inspect -f "{{.Image}}" $(docker ps -qa)); do + if [[ $(docker images --no-trunc -a | grep $c) ]]; then + ((active_images++)) + fi +done + if [ "$images" -gt 100 ]; then warn "$check_6_6" warn " * There are currently: $images images" @@ -45,6 +53,10 @@ else info " * There are currently: $images images" fi +if [[ "$active_images" -lt "$((images / 2))" ]]; then + warn " * Only $active_images out of $images are in use" +fi + # 6.7 check_6_7="6.7 - Avoid container sprawl" total_containers=$(docker info 2>/dev/null | grep "Containers" | awk '{print $2}')