From 70c6810905ecd537fa9f134605a059d88a2022c7 Mon Sep 17 00:00:00 2001 From: Raph Estrada Date: Fri, 5 Apr 2019 18:15:54 +0100 Subject: [PATCH] alias host machine ip in /etc/hosts if not already present --- docker-entrypoint.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b425dfe..51ac445 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -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 "$@"