Context, I'm currently dockerizing an application in windows containers, the application
will connect to a Sql Server database from outside the container, normally working with linux containers I could use host
driver, but since that is not available in windows containers. How could I connect to that database outside my windows container?

- 41
- 3
-
If the SQL server can be connected to over TCP, just use a normal connection string and the SQL Server driver. – Luke Briner May 03 '22 at 13:43
-
Specifically, you should be able to access the database using any valid ip address (other than the localhost address) of your host. – larsks May 03 '22 at 13:47
-
`l2bridge` should work https://learn.microsoft.com/en-us/virtualization/windowscontainers/container-networking/network-drivers-topologies – Hackerman May 03 '22 at 18:47
1 Answers
So, the answers provided before are all valid. I'd just add that while Host network is not available on Windows, you can still use the same concept - albeit a bit different.
The native network driver on Windows is Network Address Translation. With that driver, the container will get a private IP address and the ports from the container host can be mapped to the ports on the container, by use of the docker run -p 8080:80
, for example.
That way, if you want to continue to use the option to call the localhost between the app container and the database container you can. You just need to specify the port: localhost:8080. Note that if the host is not using that port, you can even map it directly, such as: docker run -p 80:80
. The caveat here is: The container host cannot be using the port already, and you can't map the same port to another container. So, if you need another instance, you can map to something like: docker run -p 81:80
.
I blogged about this here: https://cda.ms/4nB

- 406
- 1
- 5