#!/usr/bin/env bash
set +e;
handle_empty(){
while read line; do
if test -z "$line"; then
echo 'There was an empty line, exiting.' # > /dev/stderr
exit 0;
fi
echo "$line"
done;
}
export -f handle_empty;
# remove all unused / orphaned images
docker images --no-trunc | grep "<none>" | awk "{print \$3}" | handle_empty | xargs docker rmi -f | cat;
# clean up containers
docker ps --filter status=dead --filter status=exited -aq | handle_empty | xargs docker rm -v | cat;
# clean up volumes
docker volume ls -qf dangling=true | handle_empty | xargs docker volume rm | cat;
# clean up networks
docker network ls --format "{{json . }}" | jq -r '.Name' | while read name; do
if test "$name" == "interos-test"*; then
docker network rm "$name" | cat
fi
done
Last active
September 27, 2024 20:27
-
-
Save ORESoftware/bb8f97354ff38ee4a0a1dd1589af571a to your computer and use it in GitHub Desktop.
Cleanup docker artifacts/items
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment