for-win icon indicating copy to clipboard operation
for-win copied to clipboard

Internal Host DNS cannot be resolved (Windows Container 1803)

Open n-junge opened this issue 8 years ago • 109 comments

Expected behavior

According to the Docs host.docker.internal resolves the host's ip.

Actual behavior

Ping request could not find host host.docker.internal Network works fine. Pinging Host IP directly (ipconfig) works as expected.

Host: Windows 10 Enterprise Container: microsoft/windowsservercore:latest

Neither stable (18.03) nor edge (18.04) works.

Probably important side note: DNS can be resolved in Linux Container (Ubuntu)

 PS C:\> ping host.docker.internal
 Ping request could not find host host.docker.internal. Please check the name and try again.
 PS C:\> ping gateway.docker.internal
 Ping request could not find host gateway.docker.internal. Please check the name and try again.
 PS C:\> ping google.com
 
 Pinging google.com [172.217.16.78] with 32 bytes of data:
 Reply from 172.217.16.78: bytes=32 time=31ms TTL=46
 Reply from 172.217.16.78: bytes=32 time=31ms TTL=46
 Reply from 172.217.16.78: bytes=32 time=31ms TTL=46
 Reply from 172.217.16.78: bytes=32 time=31ms TTL=46
 
 Ping statistics for 172.217.16.78:
     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
 Approximate round trip times in milli-seconds:
     Minimum = 31ms, Maximum = 31ms, Average = 31ms
C:\WINDOWS\system32>docker version
Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24
 Built: Wed Mar 21 23:06:28 2018
 OS/Arch:       windows/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:      18.03.0-ce
  API version:  1.37 (minimum version 1.24)
  Go version:   go1.9.4
  Git commit:   0520e24
  Built:        Wed Mar 21 23:21:06 2018
  OS/Arch:      windows/amd64
  Experimental: false

n-junge avatar Apr 26 '18 12:04 n-junge

Hi @4xiz Thanks for reporting - I can repro and have reported it as a bug

jasonbivins avatar Apr 26 '18 19:04 jasonbivins

It's a windows daemon limitation and needs to be fix there but we will add a workaround waiting MS to fix it upstream.

ebriney avatar May 02 '18 08:05 ebriney

Release 18.05.0-ce-win66 works. Thanks.

n-junge avatar May 17 '18 15:05 n-junge

Tested it on Windows 10, Docker 18.05.0-ce-win66 (17760) and it doesn't work

image

image

image

atomaras avatar May 17 '18 19:05 atomaras

@atomaras Well the dns resolution seems to work for you too. So that's a different problem. I propose you open another issue.

n-junge avatar May 18 '18 09:05 n-junge

I just tried this and it isn't working for me. Version info:

Windows Microsoft Windows [Version 10.0.17134.112]

Docker

Client:
 Version:      18.05.0-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   f150324
 Built:        Wed May  9 22:12:05 2018
 OS/Arch:      windows/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.05.0-ce
  API version:  1.37 (minimum version 1.24)
  Go version:   go1.10.1
  Git commit:   f150324
  Built:        Wed May  9 22:29:00 2018
  OS/Arch:      windows/amd64
  Experimental: false

Ping output:

C:\>docker exec b61746027bc9 ping host.docker.internal
Ping request could not find host host.docker.internal. Please check the name and try again.

JoshCollinsMSFT avatar Jun 20 '18 22:06 JoshCollinsMSFT

@JoshCollinsMSFT I have the same windows build (17134.112) and docker (18.05.0-ce) and am also not able to resolve host.docker.internal. No joy with connection strings.

cpumanaz avatar Jun 21 '18 00:06 cpumanaz

Still not working for me with 18.06.0-ce:

docker run --rm -i microsoft/nanoserver:1709 ping host.docker.internal
Ping request could not find host host.docker.internal. Please check the name and try again.

prochnowc avatar Aug 14 '18 07:08 prochnowc

Same problem. docker.host.internal not working.

Heurazio avatar Aug 19 '18 22:08 Heurazio

@n-junge @ebriney could you please re-open this issue?

prochnowc avatar Aug 20 '18 05:08 prochnowc

So it seems the way this was fixed is that it must write out to the local hosts file on the host machine.

I have a bit of a situation as Symantec Endpoint blocks write access to the hosts file :(. Is there a better dns way of doing this? Thanks

kierzo avatar Aug 23 '18 13:08 kierzo

They are 2 separate things.

First, for dockerd to get host.docker.internal resolution we must put it in windows hosts file... So if you have endpoint protection or similar you must add an exception on com.docker.service executable.

Second, in the windows containers, we do a docker exec as soon as the container is started (using docker event) to patch the hosts file in the container (I don't know what happened if you are running in process isolation, because we don't support Windows server). So if you overwrite it at runtime you can lose those entries.

@Heurazio this is host.docker.internal, not docker.host.internal. you also have gateway.docker.internal but that is the same ip in windows containers.

@prochnowc can you try docker run microsoft/nanoserver powershell "Start-Sleep -s 2 ; if (! $(IPCONFIG /displayDNS | Select-String -Quiet -SimpleMatch host.docker.internal)) { exit 1 }"

ebriney avatar Aug 24 '18 14:08 ebriney

@ebriney Interestingly ... if i wait 2 seconds after startup i can ping host.docker.internal. I will try this again within my traefik for windows container. traefik needs the gateway address.

prochnowc avatar Aug 24 '18 14:08 prochnowc

Unfortunately it does not work.. traefik_1 | time="2018-08-25T01:30:05+02:00" level=error msg="Failed to retrieve information of the docker client and server host: error during connect: Get http://host.docker.internal:2375/v1.24/version: dial tcp: lookup host.docker.internal: getaddrinfow: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server."

Does the host.docker.internal stuff require minimum nanoserver version?

prochnowc avatar Aug 24 '18 14:08 prochnowc

@prochnowc, we execute that script as soon as we receive the start event from any windows containers:

$hostsFile = "C:\Windows\System32\drivers\etc\hosts"
$src = [System.IO.File]::ReadAllLines($hostsFile)
$a = $src += ""
For ($i=0; $i -le $a.length; $i++) {
	if ($a[$i].Contains("host.docker.internal"))
	{
		$a[$i] = "%s host.docker.internal"
		$a[$i+1] = "%s gateway.docker.internal"
		[System.IO.File]::WriteAllLines($hostsFile, [string[]]$a)
		exit
	}
}
$a = $a += "# Added by Docker for Windows"
$a = $a += "%s host.docker.internal"
$a = $a += "%s gateway.docker.internal"
$a = $a += "# End of section"
[System.IO.File]::WriteAllLines($hostsFile, [string[]]$a)

Perhaps the hosts file doesn't exist and there is an exception reading it.

ebriney avatar Aug 27 '18 08:08 ebriney

@ebriney Am I right when saying that this requires working PowerShell in the windows container? My traefik container does not have PowerShell.

prochnowc avatar Aug 27 '18 08:08 prochnowc

@prochnowc Arfff, that's why it didn't work. Do you have a suggestion on how to solve that?

ebriney avatar Aug 27 '18 08:08 ebriney

@ebriney So actually this fix only works on windows containers which have PowerShell installed (which is not the case for windows nanoserver). I dont think the hosts file editing can be done with "standard" windows command line utils. My idea would be to implement this in the docker DNS.

prochnowc avatar Aug 27 '18 15:08 prochnowc

@prochnowc hummm, nanoserver includes powershell (see command line above). And yes your image must include powershell for now. Microsoft is managing all the network part on WCOW so except if they handle it upstream we cannot do anything (but to do that I think it must be generalized in moby/moby). On Linux containers the vm traffic is going throught vpnkit so we can tweak dns requests ...

ebriney avatar Aug 27 '18 15:08 ebriney

@ebriney Sorry, but nanoserver does not include PowerShell by default. See https://docs.microsoft.com/en-us/windows-server/get-started/nano-in-semi-annual-channel. Your command line didnt work with pure nanoserver image. I had to use mcr.microsoft.com/powershell:6.0.2-nanoserver.

prochnowc avatar Aug 29 '18 08:08 prochnowc