Last active
December 2, 2015 04:18
-
-
Save alexw23/6eb66ebcaad3bd0182f8 to your computer and use it in GitHub Desktop.
Automatically add docker machines to /etc/hosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this is a short-hand function to load a docker env | |
docker-env() { | |
eval "$(docker-machine env ${1:-default})" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#add this function to your .bash_profile | |
update-docker-hosts(){ | |
# clear existing *.docker.local entries from /etc/hosts | |
sudo sed -i '' '/\.docker.local$/d' /etc/hosts | |
# iterate over each machine | |
docker-machine ls | tail -n +2 | awk '{print $1}' \ | |
| while read -r MACHINE; do | |
MACHINE_IP="$(docker-machine ip ${MACHINE} 2>/dev/null)" | |
[[ -n $MACHINE_IP ]] && sudo /bin/bash -c "echo \"${MACHINE_IP} ${MACHINE}.docker.local\" >> /etc/hosts" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment