Created
November 19, 2020 05:03
-
-
Save dinhnv/a3e02a9eeb8fc0000312e7edc04c2684 to your computer and use it in GitHub Desktop.
resolve ip for host.docker.internal DNS entry
This file contains 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
# How to use: | |
# add to Dockerfile, otherwise add to entrypoint script. For example: | |
# RUN mkdir -p /bin/docker-entrypoint/ \ | |
# && cp /tmp/scripts/docker-entrypoint/* /bin/docker-entrypoint/ \ | |
# && chmod +x -R /bin/docker-entrypoint/ \ | |
# ; | |
# ENTRYPOINT ["/bin/docker-entrypoint/resolve-docker-host-ip.sh", ...] | |
set -e | |
HOST_DOMAIN="host.docker.internal" | |
# check if the host exists - this will fail on linux | |
if dig ${HOST_DOMAIN} | grep -q 'NXDOMAIN' | |
then | |
# resolve the host IP | |
HOST_IP=$(ip route | awk 'NR==1 {print $3}') | |
# and write it to the hosts file | |
echo "$HOST_IP\t$HOST_DOMAIN" >> /etc/hosts | |
fi | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment