Connecting to host machine

I’m trying to connect to service running on the host machine from within the Docker container. According to the documentation there are two special hostnames I can use to target the host machine.

  • host.docker.internal
  • gateway.docker.internal

When I try to resolve them the container doesn’t recognise them:

C:\Windows\System32>docker container exec d6 cmd /C nslookup host.docker.internal
*** UnKnown can't find host.docker.internal: Server failed
Server:  UnKnown
Address:  172.19.48.1


C:\Windows\System32>docker container exec d6 cmd /C nslookup gateway.docker.internal
Server:  UnKnown
Address:  172.19.48.1

*** UnKnown can't find gateway.docker.internal: Server failed

I need to use them as part of a connection string:

Data Source=tcp:host.docker.internal;Initial Catalog=MyDatabase;User ID=Dave;Password=Password;

Any idea what I’m doing wrong/not doing at all?

Here’s my Docker details:

Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:12:48 2018
 OS/Arch:      windows/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.24)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:21:42 2018
  OS/Arch:      windows/amd64
  Experimental: false

Hi banksysan,

Are you using Windows Containers as opposed to Linux Containers on Windows? I’m inferring from your executing “cmd” in the container that you are using Windows Containers.

I’m not sure this feature is currently available for Windows Containers. I encountered this same issue when using Windows Containers. Please note that I did not investigate in depth but I assumed that the feature was not available for Windows Containers so I switched to Linux Containers on Windows.

Kind Regards,
Morné

Aye, Windows containers.

Thanks, at least it wasn’t just me.