Created
January 13, 2016 14:29
-
-
Save kevduggan/3942f5f405e4f49380fb to your computer and use it in GitHub Desktop.
route to docker-machine container network (from mac)
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
| #!/bin/bash | |
| # Script to instruct the Mac how to route packets to the | |
| # software defined network where containers created via docker machine | |
| # reside. This lets you casually directly to ports (ssh, http, etc. etc.) | |
| # on those containers. | |
| if [ -z "$1" ]; then | |
| echo "Please supply the name of the docker-machine VM${NC}" | |
| exit 1 | |
| fi | |
| MACHINE_NAME=$1 | |
| function ERROR(){ echo "ERROR: $*" ; } | |
| function FAIL(){ echo "FAILING: $*" ; exit 1; } | |
| if [[ 'Running' != $(docker-machine status $MACHINE_NAME) ]] | |
| then FAIL "docker-machine's $MACHINE_NAME VM not running" ; fi | |
| IP_OF_DOCKER_HOST=$(docker-machine ip $MACHINE_NAME 2> /dev/null) | |
| SDN_NET_FOR_CONTAINERS=$(docker-machine ssh $MACHINE_NAME ip route show 2> /dev/null | awk '/docker0/{print $1}' ) | |
| echo "Establishing route to $SDN_NET_FOR_CONTAINERS via $IP_OF_DOCKER_HOST" | |
| if netstat -rn | awk "\$2 == \"$IP_OF_DOCKER_HOST\" {exit(1);}" ; then | |
| sudo route -n add "$SDN_NET_FOR_CONTAINERS" "$IP_OF_DOCKER_HOST" | |
| else | |
| ERROR "Already routing something to the docker VM ..." | |
| netstat -rn \ | |
| | awk '$2 == "192.168.59.103"||/Destination.*Refs/{print;}' | |
| FAIL "... so never mind." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment