Skip to content

Instantly share code, notes, and snippets.

@magick93
Forked from mugifly/docker-clean.sh
Created October 1, 2017 06:37
Show Gist options
  • Save magick93/a3c3d5aa7e74ca1db5366559a793e59f to your computer and use it in GitHub Desktop.
Save magick93/a3c3d5aa7e74ca1db5366559a793e59f to your computer and use it in GitHub Desktop.
Cleanup Script for Docker Images and Containers
#!/bin/sh
echo -e "-- Removing exited containers --\n"
docker ps --all --quiet --filter="status=exited" | xargs --no-run-if-empty docker rm --volumes
echo -e "\n\n-- Removing untagged images --\n"
docker rmi --force $(docker images | awk '/^<none>/ { print $3 }')
echo -e "\n\n-- Removing volume directories --\n"
docker volume rm $(docker volume ls --quiet --filter="dangling=true")
echo -e "\n\nDone :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment