Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
make_docker_chooch.sh
#!/bin/bash
# Script to instruct the Mac how to route packets to the
# software defined network where containers created via boot2docker
# reside. This lets you casually directly to ports (ssh, http, etc. etc.)
# on those containers.
#
function ohfk(){ echo "FUCK: $*" ; }
function ohno(){ echo "FAILING: $*" ; exit 1; }
[ ! -z "$1" ] && DOCKER_MACHINE_ID="$1" || DOCKER_MACHINE_ID="default"
DOCKER_MACHINE_ID=$1
IP_OF_DOCKER_HOST=$(docker-machine ip $DOCKER_MACHINE_ID)
DOCKER_ROUTE_TO_SADNESS=$(docker-machine ssh $DOCKER_MACHINE_ID 'ip route show' 2> /dev/null | awk '/docker0/{print $1}' )
echo "Establishing route to $DOCKER_ROUTE_TO_SADNESS via $IP_OF_DOCKER_HOST"
if netstat -rn | awk "\$2 == \"$IP_OF_DOCKER_HOST\" {exit(1);}" ; then
sudo route -n add "$DOCKER_ROUTE_TO_SADNESS" "$IP_OF_DOCKER_HOST"
else
ohfk "Already routing something to the docker VM ..."
netstat -rn \
| awk '$2 == "192.168.59.103"||/Destination.*Refs/{print;}'
ohno "You stupid bitch."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment