Last active
September 26, 2015 00:12
-
-
Save mcoffin/fbe53c0994f5cde23cd5 to your computer and use it in GitHub Desktop.
cleandocker
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 | |
set -e | |
while getopts ":f" opt; do | |
case $opt in | |
f) | |
running_containers=$(docker ps -q) | |
if [ ! -z "$running_containers" ]; then | |
docker kill $running_containers | |
fi | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
esac | |
done | |
stale_containers=$(docker ps -a -q) | |
if [ -z "$stale_containers" ]; then | |
echo "No stale containers found." | |
else | |
docker rm -v $stale_containers | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment