Created
January 29, 2015 14:49
-
-
Save ngauthier/bd7fa10e558aa0c46e71 to your computer and use it in GitHub Desktop.
Clean up docker containers and images
This file contains 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
# Docker | |
function docker-cleanup { | |
# Find all containers that have exited | |
containers=`docker ps -a -q -f status=exited | xargs` | |
if [[ $containers ]]; then | |
# Remove exited containers | |
docker rm $containers | |
else | |
echo "No containers to remove" | |
fi | |
# Find all images that are not tagged | |
images=`docker images -a -q -f dangling=true | xargs` | |
if [[ $images ]]; then | |
# Remove untagged images | |
docker rmi $images | |
else | |
echo "No images to remove" | |
fi | |
# List containers and images that remain | |
docker ps -a | |
docker images -a | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment