#!/bin/bash
if [ "$(echo $USERNAME)" != "root" ]; then
echo "this script needs to be run by root"
exit 1
fi
if
case "${1}" in
'images')
while $(docker images -all --no-trunc | grep -vE '^[A-Z].*'); do
for image in $(docker images --all --no-trunc | grep -vE '^[A-Z].*' | perl -pe 's/.*sha256:([0-9a-z]{1,})\s+ [0-9]{1}.*/$1/g;'); do
docker rmi --force $image
done
done
;;
'containers')
for container in $(docker ps --all --no-trunc --size | grep -vE '^[A-Z].*' | perl -pe 's/^([0-9a-z]{1,})\s+ [0-9]{1}.*/$1/g;'); do
docker rm --volumes --force $container
done
;;
esac
exit 0
#!/bin/bash
if [ "$(echo $USERNAME)" != "root" ]; then
echo "this script needs to be run by root"
exit 1
fi
DOCKER_VERSION=$(docker version| grep -m 1 'Version' | perl -pe 's/.* ([1-9]{2})..*/$1/g;')
if [ "$DOCKER_VERSION" -gt "16" ]; then
docker system prune --all --force
else
while $(docker images -a --no-trunc | grep -v IMAGE); do
for image in $(docker images -a --no-trunc | perl -pe 's/\s+ / /g;' | cut -d ' ' -f 3 | grep -v IMAGE); do
docker rmi -f --no-prune $image
done
done
fi