From ca693b24397e0594b474bb41e4889d6dc900815e Mon Sep 17 00:00:00 2001 From: Mike Kolesnik Date: Tue, 24 Mar 2020 14:09:47 +0200 Subject: [PATCH] Simplify cleanup even further Following Stephen Kitt's excelent observation, it appears that -f flag is not necessary. However, after a bit further digging I've discovered that `docker system prune` will provide us with all this functionality, so why reimplment ;) For reference (if you're lazy): $ docker system prune --help Usage: docker system prune [OPTIONS] Remove unused data Options: -a, --all Remove all unused images not just dangling ones --filter filter Provide filter values (e.g. 'label==') -f, --force Do not prompt for confirmation --volumes Prune volumes $ docker system prune --volumes WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all volumes not used by at least one container - all dangling images - all dangling build cache Are you sure you want to continue? [y/N] --- scripts/shared/cleanup.sh | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/scripts/shared/cleanup.sh b/scripts/shared/cleanup.sh index 490b429ea..6965a1c95 100755 --- a/scripts/shared/cleanup.sh +++ b/scripts/shared/cleanup.sh @@ -20,36 +20,10 @@ function stop_local_registry { fi } -function cleanup_containers { - local containers=$(docker ps -qf status=exited) - if [[ -n ${containers} ]]; then - echo "Cleaning containers..." - docker rm -f ${containers} - fi -} - -function cleanup_images { - local dangling_images=$(docker images -qf dangling=true) - if [[ -n ${dangling_images} ]]; then - echo "Cleaning images..." - docker rmi -f ${dangling_images} - fi -} - -function cleanup_volumes { - local dangling_volumes=$(docker volume ls -qf dangling=true) - if [[ -n ${dangling_volumes} ]]; then - echo "Cleaning volumes..." - docker volume rm -f ${dangling_volumes} - fi -} - ### Main ### run_parallel "{1..3}" delete_cluster stop_local_registry -cleanup_containers -cleanup_images -cleanup_volumes +docker system prune --volumes -f