Skip to content

Commit

Permalink
Merge pull request #17 from Signiant/docker-host-support
Browse files Browse the repository at this point in the history
Added docker host support
  • Loading branch information
kilpatty committed May 25, 2016
2 parents 66cbe02 + 46d4531 commit d0e0123
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions docker-clean
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,21 @@ declare -a REMAINING_CONTAINERS # Currently in use
declare -a EMPTY_NETWORKS # Currently in use
#declare -a VOLUMES_TO_DELETE # Not in use

# @info: Docker host to use (default to empty or localhost).
declare DOCKER_HOST

#FUNCTIONS

# @info: Overrides the system docker daemon so we can pass in a host
# @args: Global Arguments $@
function docker(){
if [ -z "$DOCKER_HOST" ]; then
command "docker" "$@"
else
command "docker" -H "$DOCKER_HOST" "$@"
fi
}

# @info: Parses and validates the CLI arguments
# @args: Global Arguments $@
# TODO: handle use case where just -n or just -l flag is given
Expand All @@ -101,11 +113,13 @@ function parseCli(){
esac
while [[ "$#" -gt 0 ]]; do
key="$1"
val="$2"
case $key in
stop ) STOP_CONTAINERS=true; CLEAN_CONTAINERS=true; CLEAN_IMAGES=true; CLEAN_VOLUMES=true; CLEAN_NETWORKS=true ;;
images ) DELETE_TAGGED=true; CLEAN_CONTAINERS=true; CLEAN_IMAGES=true; CLEAN_VOLUMES=true; CLEAN_NETWORKS=true ;;
run ) CLEAN_CONTAINERS=true; CLEAN_IMAGES=true; CLEAN_VOLUMES=true; CLEAN_NETWORKS=true ;;
all ) STOP_CONTAINERS=true; DELETE_TAGGED=true; CLEAN_CONTAINERS=true; CLEAN_IMAGES=true; CLEAN_VOLUMES=true; CLEAN_NETWORKS=true ;;
-H | --host) DOCKER_HOST=$val; shift;;
-s | --stop) STOP_CONTAINERS=true ;;
-n | --dry-run) DRY_RUN=true ;;
-l | --log) VERBOSE=true ;;
Expand Down Expand Up @@ -155,6 +169,10 @@ function usage {
echo
echo "Additional Flag options:"
echo
echo "-H or --host Specifies the docker host to run against"
echo " Useful for docker swarm maintenance"
echo " ie: -H 127.0.0.1:4000"
echo
echo "-n or --dry-run Adding this additional flag will list items to be"
echo " removed without executing any stopping or removing commands"
echo
Expand Down Expand Up @@ -549,7 +567,7 @@ function restartMachine {
# Upstart covers SysV and OpenRC as well.
if [[ $init_system =~ upstart ]]; then
if [[ $DRY_RUN == false ]]; then
sudo service docker restart
sudo service "docker" restart
else
echo "Restart command that would be run: sudo service docker restart"
fi
Expand All @@ -561,7 +579,7 @@ function restartMachine {
fi
elif [[ $init_system =~ rc ]]; then
if [[ $DRY_RUN == false ]]; then
sudo launchctl restart docker
sudo launchctl restart "docker"
else
echo "Restart command that would be run: sudo launchctl restart docker"
fi
Expand Down

0 comments on commit d0e0123

Please sign in to comment.