Skip to content

Instantly share code, notes, and snippets.

@steevehook
Forked from skatsuta/docker-machine.sh
Created March 18, 2018 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steevehook/94988593169514c84258a27686aa1feb to your computer and use it in GitHub Desktop.
Save steevehook/94988593169514c84258a27686aa1feb to your computer and use it in GitHub Desktop.
Tired of running `eval "$(docker-machine env host)"` every time? Just paste this in .bashrc / .zshrc. This script automatically sets environment variables for one of running host machines in Docker Machine.
# check if `docker-machine` command exists
if command -v docker-machine > /dev/null; then
# fetch the first running machine name
local machine=$(docker-machine ls | grep "Running" | head -n 1 | awk '{ print $1 }')
if [ "$machine" != "" ]; then
eval "$(docker-machine env $machine)"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment