-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerclean.sh
More file actions
13 lines (9 loc) · 815 Bytes
/
dockerclean.sh
File metadata and controls
13 lines (9 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
sudo find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)') | xargs -r rm -fr
# all
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v && docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi && sudo find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)') | xargs -r rm -fr