Skip to content

Instantly share code, notes, and snippets.

@maximd
Last active September 10, 2016 11:37
Show Gist options
  • Save maximd/1e0d0559fc873153588ad0504a53e238 to your computer and use it in GitHub Desktop.
Save maximd/1e0d0559fc873153588ad0504a53e238 to your computer and use it in GitHub Desktop.
docker-gc
#!/usr/bin/env bash
#
# docker-gc - remove stopped docker containers and images
#
# inspired by:
# - https://forums.docker.com/t/command-to-remove-all-unused-images/20/2
# - http://stackoverflow.com/a/24681946/576371
docker ps -qaf status=exited | xargs docker rm
docker images -qf dangling=true | xargs docker rmi
# it would be better to use "--no-run-if-empty" option for xargs as described in https://gist.github.com/ngpestelos/4fc2e31e19f86b9cf10b#gistcomment-1769502
# but xargs does not support this option on Mac
# more information about dangling images at http://www.projectatomic.io/blog/2015/07/what-are-docker-none-none-images/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment