Skip to content

Instantly share code, notes, and snippets.

@jarek-przygodzki
Last active June 17, 2016 10:25
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 jarek-przygodzki/1d158c2bf002e5fc9a7e555da09566e4 to your computer and use it in GitHub Desktop.
Save jarek-przygodzki/1d158c2bf002e5fc9a7e555da09566e4 to your computer and use it in GitHub Desktop.
Docker Clean Up!
#!/bin/bash
# Author: Jarek Przygódzki <jarek.przygodzki@gmail.com>
#
# Docker 1.9+
#
# In Docker 1.9, there is the ability to manage volumes better
# with docker volume (see https://github.com/docker/docker/pull/14242)
#
# Delete all stopped containers
echo "Delete all stopped containers"
docker ps -q -f status=exited | xargs --no-run-if-empty docker rm
# Delete all dead containers
echo "Delete all dead containers"
docker ps -q -f status=dead | xargs --no-run-if-empty docker rm
# Delete all dangling (unused) images
echo "Delete all dangling (unused) images"
docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi
# Delete all dangling (orphaned) volumes
echo "Delete all dangling (orphaned) volumes"
docker volume ls -qf dangling=true | xargs --no-run-if-empty docker volume rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment