Last active
April 1, 2019 16:22
-
-
Save jkuchar/499cde5952caab68dcdbe6a28dd9309f to your computer and use it in GitHub Desktop.
Docker daemon: clean garbage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @link https://gist.github.com/jkuchar/499cde5952caab68dcdbe6a28dd9309f | |
# @link http://blog.yohanliyanage.com/2015/05/docker-clean-up-after-yourself/ | |
# @link http://www.projectatomic.io/blog/2015/07/what-are-docker-none-none-images/ | |
# | |
# This will reclaim space and inodes used by stopped containers, dangling images and dangling volumes. | |
# I use this in GitLab CI multi runner with Docker version 1.13.0; should work with Docker >1.9.0 | |
# Currently I run this script every day in cron. | |
echo "Containers cleanup: removing exited containers" | |
docker rm -v $(docker ps -a -q -f status=exited) | |
echo "Images cleanup: removing dangling containers" | |
docker rmi $(docker images -f "dangling=true" -q) | |
echo "Volumes cleanup: removing dangling volumes" | |
docker volume rm $(docker volume ls -qf dangling=true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment