Skip to content

Instantly share code, notes, and snippets.

@faceleg
Forked from iansinnott/docker_wrapper.sh
Last active August 29, 2015 14:26
Show Gist options
  • Save faceleg/898a1fa0546f4c01d99b to your computer and use it in GitHub Desktop.
Save faceleg/898a1fa0546f4c01d99b to your computer and use it in GitHub Desktop.
Automatically set up boot2docker on a Mac whenever `docker` is called
#!/bin/bash
# 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_IP=$(boot2docker ip 2>/dev/null)
export DOCKER_HOST="tcp://$DOCKER_IP:2375"
# 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