Permalink
Browse files

Only remove containers and images if there is something to delete. Cl…

…oses #137 and fixes longstanding TODO.
  • Loading branch information...
darron committed Jun 20, 2015
1 parent 5a68943 commit 0819f6ce833f72e91f05546d09875f3b0a08ac27
Showing with 16 additions and 7 deletions.
  1. +16 −7 bin/octo
View
@@ -643,14 +643,23 @@ case "$1" in
;;
clean)
echo "Cleaning old exited containers."
# TODO: Errors if there's no containers - annoying.
sudo docker -H $DOCKER_HOST ps -a | grep -v "$BUILD_ORG_NAME\/.*\_data*" | grep "Exit" | cut -d ' ' -f 1 | xargs sudo docker -H $DOCKER_HOST rm
echo "Showing all remaining containers."
CONTAINERS_TO_DELETE=$(sudo docker -H $DOCKER_HOST ps -a | grep -v "$BUILD_ORG_NAME\/.*\_data*" | grep "Exit" | cut -d ' ' -f 1)
if [ "$CONTAINERS_TO_DELETE" != '' ] ; then
echo "Cleaning old exited containers."
echo $CONTAINERS_TO_DELETE | xargs sudo docker -H $DOCKER_HOST rm
else
echo "No exited containers to delete."
fi
echo "Showing remaining containers."
sudo docker -H $DOCKER_HOST ps -a
echo "Cleaning out all unused images."
sudo docker -H $DOCKER_HOST images | grep "\<none\>" | awk '{ print $3 }' | xargs sudo docker -H $DOCKER_HOST rmi
echo "Showing all remaining images."
IMAGES_TO_DELETE=$(sudo docker -H $DOCKER_HOST images | grep "\<none\>" | awk '{ print $3 }')
if [ "$IMAGES_TO_DELETE" != '' ] ; then
echo "Cleaning out all unused images."
echo $IMAGES_TO_DELETE | xargs sudo docker -H $DOCKER_HOST rmi
else
echo "No unused images to delete."
fi
echo "Showing remaining images."
sudo docker -H $DOCKER_HOST images
;;

0 comments on commit 0819f6c

Please sign in to comment.