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}')