Created
August 18, 2016 07:17
-
-
Save mugifly/ffd3973d34c4a1b7c303cf024944a6f4 to your computer and use it in GitHub Desktop.
Cleanup Script for Docker Images and Containers
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
#!/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
Is there a special reason why you use "xargs" in the first one and "$(...)" in the others ? Thank you 😅 I think I am missing something subtle.