Skip to content

Instantly share code, notes, and snippets.

@jkuchar
Last active April 1, 2019 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkuchar/499cde5952caab68dcdbe6a28dd9309f to your computer and use it in GitHub Desktop.
Save jkuchar/499cde5952caab68dcdbe6a28dd9309f to your computer and use it in GitHub Desktop.
Docker daemon: clean garbage
# @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