Windows Containers, how to access in Windows host machine port from container?

I’m using the new “Containers” on Windows Server 2016 (> TP5) and I need to connect my DOT.NET application to my SQL Server on my Windows Machine.

How can I access my Windows machine IP address from Docker container?

I can’t access my SQL Server database just from my containers, I can access it from anywhere in the world without problems.

I already tried --net="host", "bridge", "nat" but nothing.How to do that?

Host ports are available on the default gateway of the container network interface. Below I access the Docker Engine API on the host.

PS C:\> ipconfig

Windows IP Configuration


Ethernet adapter vEthernet (Temp Nic Name):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::99d:bf5e:8700:56df%26
   IPv4 Address. . . . . . . . . . . : 172.27.219.121
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.27.208.1
PS C:\> curl http://172.27.208.1:2375/info -UseBasicParsing
StatusCode        : 200
StatusDescription : OK
...
2 Likes

I’m looking to connect from my container to Windows SQL Server. From container to Windows, not viceversa.

I know - you should be able to connect on :1433 from inside the container. The default gateway IP for the container can be learnt by running ipconfig.

Hi,
Thanks for suggestion, but when i tried the same, i got the following error.

PS C:> ipconfig

Windows IP Configuration
Ethernet adapter Ethernet 2:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::d06d:8d32:c134:d63a%5
IPv4 Address. . . . . . . . . . . : 172.29.116.48
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . : 172.29.112.1
PS C:> curl http://172.29.112.1:2375/containers/json -UseBasicParsing
curl : Unable to connect to the remote server
At line:1 char:1

  • curl http://172.29.112.1:2375/containers/json -UseBasicParsing
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

It looks like you’re trying to connect to the docker engine. Did you make it listen on port 2375 (in addition to the default named pipe)?

These commands will not work on Docker for Windows, only Windows Server or with the Windows-native Docker daemon deployed in stand-alone mode:

dockerd --unregister-service
net stop docker
dockerd -H npipe:////./pipe/docker_engine -H 0.0.0.0:2375 --register-service
net start docker
1 Like

Here’s something to try…

make sure Kitematic is installed then click on your running container as seen below.

It will tell you what port to use to access the container… this can be configured, if necessary

1 Like