Skip to content

Commit

Permalink
Simplify cleanup even further
Browse files Browse the repository at this point in the history
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=<key>=<value>')
  -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]
  • Loading branch information
mkolesnik authored and mangelajo committed Mar 25, 2020
1 parent 94c4d89 commit ca693b2
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions scripts/shared/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ca693b2

Please sign in to comment.