Skip to content

Commit c17ca16

Browse files
author
Antonio Ojea
committed
detect docker host IP based on the default route
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.
1 parent 83b25fd commit c17ca16

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

images/base/files/usr/local/bin/entrypoint

+2-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ enable_network_magic(){
337337
# first we need to detect an IP to use for reaching the docker host
338338
local docker_host_ip
339339
docker_host_ip="$( (getent ahostsv4 'host.docker.internal' | head -n1 | cut -d' ' -f1) || true)"
340-
if [[ -z "${docker_host_ip}" ]]; then
340+
# if the ip doesn't exist or is a loopback address use the default gateway
341+
if [[ -z "${docker_host_ip}" ]] || [[ $docker_host_ip =~ ^127\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
341342
docker_host_ip=$(ip -4 route show default | cut -d' ' -f3)
342343
fi
343344

0 commit comments

Comments
 (0)