Last active
June 26, 2016 09:33
-
-
Save halcwb/17096fc8066661430f06993e9e2212c4 to your computer and use it in GitHub Desktop.
Small shell command to list or remove docker volumes
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
#!/usr/bin/env bash | |
# Get the current docker version | |
echo "List or remove docker volumes" | |
echo "This only works for docker version 1.9 or higher" | |
echo "Docker version:" | |
docker -v | |
# Differentiate remove command for linux and os x | |
function remove_volumes() { | |
if [[ "$OSTYPE" == "linux"* ]]; then | |
echo "Remove for Linux" | |
docker volume ls -qf dangling=true | xargs -r docker volume rm | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
echo "Remove for Darwin" | |
docker volume ls -qf dangling=true | xargs docker volume rm | |
fi | |
} | |
# Check arg for listing or removing | |
if [[ "$@" == "-ls"* ]]; then | |
echo "Listing Volumes" | |
docker volume ls -qf dangling=true #| xargs -r docker volume rm | |
elif [[ "$@" == "-rm"* ]]; then | |
echo "Removing volumes" | |
remove_volumes | |
echo "Volumes left:" | |
docker volume ls -qf dangling=true #| xargs -r docker volume rm | |
else | |
echo "$@" | |
echo "not a valid argument, use -lf or -rm" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment