- gather a bunch of useful clean up commands from below and put into a daily cron job, which should be provisioned to all servers kkthx
- pipe to xargs using -r, e.g.
$(docker ps -a -q -f status=exited) | xargs -r docker rm -v
to avoid getting docker rm errors if empty input - be careful about removing exited containers together with data containers, e.g.
docker rm -v $(docker ps -a -q -f status=exited)
- think about creating commands that only remove containers that exited some time ago, e.g.
docker ps -a | grep Exited | grep "days ago" | awk '{print $1}' | xargs docker rm
sudo apt-get install python-pip
pip install --upgrade pip
sudo pip install git+https://github.com/Yelp/docker-custodian.git#egg=docker_custodian
dcgc --help
- remove stopped containers and unused images older than 2 days
dcgc --max-image-age 2days
- you can use
--dry-run
flag to test it out
remove all stopped containers, all volumes not used by at least one container, all networks not used by at least one container, all dangling images
docker system prune
(available at least in docker 1.13)
remove all stopped containers, all volumes not used by at least one container, all networks not used by at least one container, all images without at least one container associated to them
docker system prune -a
(d:o)
docker image prune
(available at least in docker 1.13) ordocker rmi -f $(docker images -q -f dangling=true)
docker image prune -a
(available at least in docker 1.13-rc4)
docker rmi -f $(docker images -q)
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
docker rm -f $(docker ps -aq)
docker volume rm $(docker volume ls -qf dangling=true)
docker-gc
https://github.com/spotify/docker-gc