Docker 容器可以访问互联网,但不能访问本地网络

use*_*073 8 docker docker-network

我有一个在 win server 2016 上运行的 Windows docker 容器

容器中运行的站点可以从网络上的其他节点访问。

容器可以访问互联网(它可以访问网络外部的第 3 方节点),但无法连接到网络中的其他节点。

当容器中运行的应用程序尝试访问网络中另一台计算机 (machine_name) 上的服务时,会出现以下错误:

The remote name could not be resolved: machine_name

当应用程序尝试连接到网络上的数据库时:

A network-related or instance-specific error occurred while establishing a connection

所以看起来容器没有访问权限或者找不到内网机器

我跑了 docker exec -ti e87633560c6c ipconfig /all 并得到以下信息:

Windows IP Configuration

   Host Name . . . . . . . . . . . . : gmsa_acct
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter vEthernet (Container NIC 0b35fe9f):

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter #2
   Physical Address. . . . . . . . . : 00-15-5D-30-F4-1D
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::7939:903e:141f:5c98%24(Preferred)
   IPv4 Address. . . . . . . . . . . : 172.22.223.136(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.22.208.1
   DNS Servers . . . . . . . . . . . : 172.22.208.1
                                       10.xxx
                                       10.xxx
   NetBIOS over Tcpip. . . . . . . . : Disabled

Run Code Online (Sandbox Code Playgroud)

我在运行容器的机器上运行了这个命令

docker exec e87633560c6c nltest /sc_verify:mydomain.com
Flags: b0 HAS_IP  HAS_TIMESERV
Trusted DC Name \\D1dns01.mydomain.com
Trusted DC Connection Status Status = 0 0x0 NERR_Success
Trust Verification Status = 0 0x0 NERR_Success
The command completed successfully
Run Code Online (Sandbox Code Playgroud)

奇怪的是,同一个容器在另一台主机上运行没有任何问题。我们现在尝试在新主机上运行它并遇到上述问题。

任何帮助表示赞赏。

谢谢。

编辑:我可以通过 IP 地址而不是机器名称进行连接。如何通过机器名称进行连接?

a_m*_*ati 0

当 Docker 为其运行的容器创建网络时,默认情况下它会创建一个类型为“bridge”的 NAT 网络。您可以使用命令详细了解容器的网络docker network ls,结果如下:

\n
NETWORK ID          NAME                DRIVER              SCOPE\n17e324f45964        bridge              bridge              local\n6ed54d316334        host                host                local\n7092879f2cc8        none                null                local\n
Run Code Online (Sandbox Code Playgroud)\n

您可以尝试使用“主机”网络配置:

\n
\n

如果对容器使用主机网络模式,则该容器\xe2\x80\x99s\n网络堆栈不会与 Docker 主机隔离(该容器\n共享主机\xe2\x80\x99s 网络命名空间),并且该容器不会与 Docker 主机隔离。没有分配到自己的 IP 地址。例如,如果您运行绑定到端口 80 的容器,并且使用主机网络,则容器\xe2\x80\x99s\n应用程序可在主机\xe2\x80\x99s IP 地址的端口 80 上使用。

\n
\n

使用主机网络

\n

  • 主机网络似乎在 Windows 上也不可用 (2认同)