cfg/bin/docker-clean

16 lines
453 B
Text
Raw Permalink Normal View History

2016-07-21 13:48:49 +00:00
#!/bin/bash
set -euo pipefail
2016-07-21 13:48:49 +00:00
if [ -e "${HOME}/bin/script_framework.sh" ]; then
source "${HOME}/bin/script_framework.sh"
else
function step() { echo $@; }
fi
step "Removing containers created / exited >= ~1h ago..."
CONTAINERS=$(docker ps -a | gawk '/(hours?|days?|weeks?|months?) ago\s+(Created|Exited)/{ print $1 }' | xargs)
[ -n "${CONTAINERS}" ] && docker rm ${CONTAINERS}
step "Removing unused and dangling images..."
docker image prune -a -f