如何从Windows Docker容器连接到主机上的SQLEXPRESS

我正在开发一个在Docker中运行的ASP.NET Core应用程序。 在开发过程中,我希望容器连接到在我的开发机器上运行的SQLEXPRESS,这也是我的docker主机。 但是,尽我所能说,容器根本无法到达主机。 我无法连接到SQL或从容器ping主机IP。 我能够在我的主机上本地运行应用程序,并连接到SQL Server就好了,所以我怀疑如果我可以从容器中ping主机,我可以连接到SQL。

主机在主适配器上的IP地址为10.0.0.5,在“HNS内部网卡”上IP地址为172.30.96.1,我认为这是Docker正在使用的IP地址。

为了testing基本的连接性,我尝试从容器内部ping:

docker exec -i containername cmd c:\app ping 10.0.0.5 Request timed out c:\app ping 172.30.96.1 Request timed out 

基于一些类似的post,我也试图连接到一个“主机”networking,但是这显然不适用于这个版本的docker。 我怀疑这是更多的Linux:

 docker run --net="host" ... network host not found. 

我还发现了一个类似的Windows 10的post,提出了一个“透明”的networking。 有了这个networking,我无法连接进出:

 docker network create --driver transparent trans --gateway 10.0.0.1 --subnet 10.0.0.1/16 docker run --net=trans ... docker exec -i containername cmd c:\app> ipconfig IPv4 address: 10.0.205.104 c:\app> ping 10.0.0.5 Request timed out c:\app> exit ping 10.0.205.104 Request timed out 

这是我的docker信息:

  Containers: 1 Running: 1 Paused: 0 Stopped: 0 Images: 10 Server Version: 17.03.2-ee-5 Storage Driver: windowsfilter Windows: Logging Driver: json-file Plugins: Volume: local Network: l2bridge l2tunnel nat null overlay transparent Log: Swarm: inactive Default Isolation: process Kernel Version: 10.0 14393 (14393.1593.amd64fre.rs1_release.170731-1934) Operating System: Windows Server 2016 Datacenter OSType: windows Architecture: x86_64 CPUs: 4 Total Memory: 8GiB Name: danielsdev5 ID: XLTN:PBAQ:BU7C:BMR6:O2VJ:DQKQ:P7TY:6QR7:NWEI:GEIF:OFND:ZVFE Docker Root Dir: C:\ProgramData\Docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false