Docker Community Forums

Share and learn in the Docker community.

Can't access Windows host machine by name from a container

I have a Windows 10 laptop running SQL Server and Docker for Windows. I have a linux container running a .NET Core app trying to connect to SQL Server on the laptop. I’ve found that on my work network, I can connect using my machine name. When travelling, I can’t use my machine name and must use the local IP address assigned to me by the network I’m on. It seems that Docker uses 8.8.8.8 for DNS name resolution in these cases. Is there some way to access my laptop by name from within my containers? Why does Docker seem to need a DNS server to resolve the name of the computer it’s running on?

Any help would be appreciated. It’s tiring changing my connection string every day to reflect the IP address of the network I connect to in each city I visit.

Thanks in advance,
Mike

While it does not answer this exact question for development, depending on the features you need, you may consider trying https://www.microsoft.com/en-us/sql-server/sql-server-vnext-including-Linux.

Hi Chris,

Thanks for the reply. In this case, I’m not looking to run SQL Server on Linux, but rather attach to an existing SQL Server on my Windows laptop. More broadly, I’m wondering why I can’t see the Windows machine that’s running Docker from my Docker containers unless I’m on a network with a DNS server that lists my laptop? I realize that the containers will connect via a network connection, but shouldn’t the host machine be a special case that doesn’t require a DNS server? I can now work around it as I move from network to network by obtaining my IP address on each network and reconfiguring my app each time, but this seems to be a pretty common scenario that should be handled. Why should my containers not be able to see my laptop if I happen to be in a Starbucks or a hotel or a lecture hall? I appreciate your reply.

Hi Mike,

The only think I can come up with is to hack around with my hosts file and use --add-host in the docker run command.

I added

docker run --add-host=“mycomputer:172.23.48.1” …

To get that IP I queried the internal NIC that is connected to the NAT

$ipaddr = (Get-NetIPAddress -InterfaceAlias “vEthernet (HNS Internal NIC)”).IPAddress[1]

I figured it was that network adapter by looking at the IP range specified for the DockerNAT virtual switch NAT and finding the virtual adapter on my host that had and IP in that range.

I can now ping the same name inside and outside the container.