Skip to content

Instantly share code, notes, and snippets.

@mcoffin
Last active September 26, 2015 00:12
Show Gist options
  • Save mcoffin/fbe53c0994f5cde23cd5 to your computer and use it in GitHub Desktop.
Save mcoffin/fbe53c0994f5cde23cd5 to your computer and use it in GitHub Desktop.
cleandocker
#!/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