Skip to content

Instantly share code, notes, and snippets.

@ianblenke
Last active August 29, 2015 14:14
Show Gist options
  • Save ianblenke/9be295274cc83b3fad3e to your computer and use it in GitHub Desktop.
Save ianblenke/9be295274cc83b3fad3e to your computer and use it in GitHub Desktop.
Preparing the DOCKER environment variables for fig to use, as pulled from a docker-machine config
if which docker-machine > /dev/null 2>&1; then
export DOCKER_HOST=""
alias d="docker $(docker-machine config $(docker-machine ls -q | head -1))"
declare -a lines=( $(docker-machine config $(docker-machine ls -q | head -1)) )
for (( i = 0; i < ${#lines[*]}; ++ i )) ; do
line="${lines[$i]}"
if [ "$line" = "--tls" ]; then
export DOCKER_TLS_VERIFY=true
fi
if echo "$line" | grep tlscert > /dev/null; then
docker_cert_file=$(echo "$line" | cut -d= -f2)
export DOCKER_CERT_PATH=$(dirname $docker_cert_file)
fi
if [ "$line" = "-H" ]; then
DOCKER_HOST="${lines[$i+1]}"
fi
done
fi
@ianblenke
Copy link
Author

I put this in my dotfiles as ~/.bash_profile.d/docker-machine.sh so that it is sourced automagically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment