merge: work
This commit is contained in:
commit
c64c8ea0c8
@ -58,6 +58,18 @@ alias dknpf='docker network prune -f'
|
||||
alias dknrm='docker network rm'
|
||||
alias dknrmf='docker network rm -f'
|
||||
|
||||
# system
|
||||
alias dks='docker system'
|
||||
alias dksdf='docker system df'
|
||||
alias dksp='docker system prune'
|
||||
alias dkspa='docker system prune -a'
|
||||
alias dkspaf='docker system prune -af'
|
||||
alias dkspf='docker system prune -f'
|
||||
alias dkspv='docker system prune --volumes'
|
||||
alias dkspva='docker system prune --volumes -a'
|
||||
alias dkspvaf='docker system prune --volumes -af'
|
||||
alias dkspvf='docker system prune --volumes -f'
|
||||
|
||||
# docker-compose
|
||||
alias dc='docker-compose'
|
||||
alias dcd='docker-compose down'
|
||||
|
109
bin/dkpurge
109
bin/dkpurge
@ -1,109 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$1" == '-h' ] || [ "$1" == '--help' ]; then
|
||||
cat << EOF
|
||||
Usage: $0 [Default-answer]
|
||||
Delete all Docker ressources.
|
||||
root permission not necessary so the binary can be placed in
|
||||
$HOME/[.local/]bin.
|
||||
|
||||
| Ressource | Answer | Description |
|
||||
| ---------- | ------ | -------------------------- |
|
||||
| Containers | [Y]es | Remove stopped containers |
|
||||
| | [A]ll | Remove all containers |
|
||||
| | [N]o | Skip |
|
||||
| | | |
|
||||
| Volumes | [Y]es | Remove unused volumes |
|
||||
| | [A]ll | Remove unused volumes |
|
||||
| | [N]o | Skip |
|
||||
| | | |
|
||||
| Images | [Y]es | Remove unused local images |
|
||||
| | [A]ll | Remove all unused images |
|
||||
| | [N]o | Skip |
|
||||
| | | |
|
||||
| Networks | [Y]es | Remove unused networks |
|
||||
| | [A]ll | Remove unused networks |
|
||||
| | [N]o | Skip |
|
||||
EOF
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
|
||||
PS="$(docker container ls -aq 2> /dev/null)"
|
||||
|
||||
if [ "$?" != 0 ] && [ "$EUID" != 0 ]; then
|
||||
sudo -- "$0" "$@"
|
||||
exit
|
||||
fi
|
||||
|
||||
VOL="$(docker volume ls -q 2> /dev/null)"
|
||||
IMG="$(docker images -q 2> /dev/null)"
|
||||
NET="$(docker network ls -q 2> /dev/null)"
|
||||
|
||||
DEFAULT_NET="$(docker network ls -q -f name=bridge -f name=host -f name=none)"
|
||||
|
||||
ANS="$1"
|
||||
[ -z "$1" ] && READ="read -r ANS"
|
||||
|
||||
if [ -n "$PS" ]; then
|
||||
docker container ls -a
|
||||
|
||||
echo -n "Prune Containers? [Y/n/a] "
|
||||
$READ
|
||||
case "${ANS,,}" in
|
||||
'y'|'yes'|'')
|
||||
docker rm $PS 2> /dev/null
|
||||
;;
|
||||
'a'|'all')
|
||||
docker rm -f $PS 2> /dev/null
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -n "$VOL" ]; then
|
||||
echo
|
||||
docker volume ls
|
||||
|
||||
echo -n "Prune Volumes? [Ya/n] "
|
||||
$READ
|
||||
case "${ANS,,}" in
|
||||
'y'|'yes'|'a'|'all'|'')
|
||||
docker volume rm -f $VOL 2> /dev/null
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -n "$IMG" ]; then
|
||||
echo
|
||||
docker image ls
|
||||
|
||||
echo -n "Prune Images? [Y/n/a] "
|
||||
$READ
|
||||
case "${ANS,,}" in
|
||||
'y'|'yes'|'')
|
||||
for img in $IMG; do
|
||||
if docker image inspect "$img" | grep '"RepoTags": \[]' &> /dev/null; then
|
||||
TO_CLEAN="$TO_CLEAN $img"
|
||||
fi
|
||||
done
|
||||
docker image rm -f $TO_CLEAN 2> /dev/null
|
||||
;;
|
||||
'a'|'all')
|
||||
docker image rm -f $IMG 2> /dev/null
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -n "$NET" ] && [ "$NET" != "$DEFAULT_NET" ]; then
|
||||
echo
|
||||
docker network ls
|
||||
|
||||
echo -n "Prune Networks? [Ya/n] "
|
||||
$READ
|
||||
case "${ANS,,}" in
|
||||
'y'|'yes'|'a'|'all'|'')
|
||||
docker network prune -f
|
||||
;;
|
||||
esac
|
||||
fi
|
Loading…
Reference in New Issue
Block a user