Skip to content

Commit

Permalink
detect docker host IP based on the default route
Browse files Browse the repository at this point in the history
we were using the well known name host.docker.internal to get the
host IP address, however, it seems that in some systems it resolves
to a loopback address. We use this address to replace the embedded
docker dns IP address in the resolv.conf.
We can't use a loopback address, because coredns obtains the upstream
dns resolvers from the resolv.conf, and evidentelly, it crashes if the
upstream DNS resolver is a loopback, because it meains that is itself,
and that is a loop.
  • Loading branch information
Antonio Ojea committed Mar 27, 2021
1 parent 83b25fd commit c17ca16
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion images/base/files/usr/local/bin/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ enable_network_magic(){
# first we need to detect an IP to use for reaching the docker host
local docker_host_ip
docker_host_ip="$( (getent ahostsv4 'host.docker.internal' | head -n1 | cut -d' ' -f1) || true)"
if [[ -z "${docker_host_ip}" ]]; then
# if the ip doesn't exist or is a loopback address use the default gateway
if [[ -z "${docker_host_ip}" ]] || [[ $docker_host_ip =~ ^127\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
docker_host_ip=$(ip -4 route show default | cut -d' ' -f3)
fi

Expand Down

0 comments on commit c17ca16

Please sign in to comment.