Skip to content

Instantly share code, notes, and snippets.

@agudulin
Forked from iansinnott/docker_wrapper.sh
Last active August 29, 2015 14:10
Show Gist options
  • Save agudulin/2b9cb1329c2098b48076 to your computer and use it in GitHub Desktop.
Save agudulin/2b9cb1329c2098b48076 to your computer and use it in GitHub Desktop.
# A wrapper for the docker binary. Checks to make sure the docker host is
# set before executing docker commands.
docker() {
# Start the daemon if it's not running
if [ $(boot2docker status) != 'running' ]; then
echo 'Starting the Docker daemon.'
boot2docker start
fi
if [ -z $DOCKER_HOST ] || [ -z $DOCKER_IP ]; then
# Store the docker binary path
DOCKER=$(which docker)
# All 'echo' commands are unecessary, but it lets you know
# if this block of code was run or not.
echo 'Setting Docker host...'
# Grab the ip address from boot2socker. DOCKER_IP is not
# necessary to run docker, but it comes in handy (see readme).
export DOCKER_CERT_PATH="$HOME/.boot2docker/certs/boot2docker-vm"
export DOCKER_TLS_VERIFY=1
export DOCKER_IP=$(boot2docker ip 2>/dev/null)
export DOCKER_HOST="tcp://$DOCKER_IP:2376"
# Confirm that variables were exported via the command line.
echo " DOCKER_IP=$DOCKER_IP"
echo " DOCKER_HOST=$DOCKER_HOST"; echo
fi
# Execute docker with all arguments.
DOCKER "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment