Forked from fntlnz/establish-routing-to-docker-osx-container-network
Last active
March 29, 2019 18:30
-
-
Save metacollin/c65638a68a75a62b884b8d7e664b1d15 to your computer and use it in GitHub Desktop.
make_docker_chooch.sh
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 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