alias host machine ip in /etc/hosts if not already present

This commit is contained in:
Raph Estrada 2019-04-05 18:15:54 +01:00
parent 8c590fc68f
commit 70c6810905

View file

@ -31,4 +31,17 @@ if [ "$socketMissing" = 1 -a "$1" = forego -a "$2" = start -a "$3" = '-r' ]; the
exit 1
fi
# alias host machine IP if not already present
DOCKER_HOST_IP=$(dig +short -4 host.docker.internal)
if [[ -z $DOCKER_HOST_IP ]]; then
echo "host.docker.internal not resolved, attempting to identify docker host ip..."
DOCKER_HOST_IP=`/sbin/ip route|awk '/default/ { print $3 }'`
echo "found host.docker.internal at $DOCKER_HOST_IP, adding to /etc/hosts..."
echo "$DOCKER_HOST_IP host.docker.internal" >> /etc/hosts
echo "$DOCKER_HOST_IP docker.for.mac.localhost" >> /etc/hosts
echo "$DOCKER_HOST_IP docker.for.win.localhost" >> /etc/hosts
else
echo "host.docker.internal resolved to $DOCKER_HOST_IP, not modifying /etc/hosts"
fi
exec "$@"