Skip to content

Instantly share code, notes, and snippets.

@caktux
Last active December 26, 2015 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caktux/7159822 to your computer and use it in GitHub Desktop.
Save caktux/7159822 to your computer and use it in GitHub Desktop.
Docker cleanup
# ~/.bashrc function
# Use `docker-cleanup --dry-run` to see what would be deleted.
function docker-cleanup {
EXITED=$(docker ps -q -f status=exited)
DANGLING=$(docker images -q -f "dangling=true")
if [ "$1" == "--dry-run" ]; then
echo "==> Would stop containers:"
echo $EXITED
echo "==> And images:"
echo $DANGLING
else
if [ -n "$EXITED" ]; then
docker rm $EXITED
else
echo "No containers to remove."
fi
if [ -n "$DANGLING" ]; then
docker rmi $DANGLING
else
echo "No images to remove."
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment