【问题标题】:No internet from within local Service Fabric Mesh Container本地 Service Fabric Mesh 容器内没有互联网
【发布时间】:2019-04-12 11:23:41
【问题描述】:

我在本地 PC 上使用 Service Fabric Mesh,但在 (Windows) 容器内访问 Internet 时遇到了困难。

我正在使用 Visual Studio 2017 中的标准 Web 应用模板:

public static async Task<int> Main(string[] args)
    {
        try
        {
            var test = await (new System.Net.Http.HttpClient()).GetStringAsync("http://google.com");
            Console.WriteLine(test);

您可能希望打印出一些 HTML,但我得到了这个异常:

System.Net.Http.HttpRequestException:不知道这样的主机---> System.Net.Sockets.SocketException:不知道这样的主机 在 System.Net.Http.ConnectHelper.ConnectAsync(字符串主机,Int32 端口,CancellationToken 取消令牌) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Http.ConnectHelper.ConnectAsync(字符串主机,Int32 端口,CancellationToken 取消令牌) 在 System.Threading.Tasks.ValueTask`1.get_Result() 在 System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage 请求,CancellationToken 取消令牌) 在 System.Threading.Tasks.ValueTask`1.get_Result() 在 System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask) 在 System.Threading.Tasks.ValueTask`1.get_Result() 在 System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage 请求,布尔 doRequestAuth,CancellationToken 取消令牌) 在 System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage 请求,CancellationToken cancelToken) 在 System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage 请求, CancellationTokenSource cts, Boolean disposeCts) 在 System.Net.Http.HttpClient.GetStringAsyncCore(任务`1 getTask) 在 Web1.Program.Main(String[] args)

使用的基本 docker 映像是 microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1709,如果我运行: docker run microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1709 ping google.com 然后我得到:

PS C:\Windows\system32> docker run microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1709 ping google.com

Pinging google.com [172.217.168.238] with 32 bytes of data:
Reply from 172.217.168.238: bytes=32 time=16ms TTL=56
Reply from 172.217.168.238: bytes=32 time=15ms TTL=56
Reply from 172.217.168.238: bytes=32 time=15ms TTL=56
Reply from 172.217.168.238: bytes=32 time=16ms TTL=56

Ping statistics for 172.217.168.238:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 15ms, Maximum = 16ms, Average = 15ms

我做错了什么?

更新 1:

当我直接运行 Docker 映像时,我得到:

PS C:\Users\XXX> docker run microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1803 ipconfig.exe /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : XXX
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : XXX

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : XXX
   Description . . . . . . . . . . . : Microsoft Hyper-V Network Adapter
   Physical Address. . . . . . . . . : 00-15-5D-38-EE-09
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::1c14:1ec3:9b85:5f56%4(Preferred)
   IPv4 Address. . . . . . . . . . . : 172.20.192.4(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.20.192.1
   DHCPv6 IAID . . . . . . . . . . . : 67114333
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-23-7C-13-F1-00-15-5D-38-EE-09
   DNS Servers . . . . . . . . . . . : 172.20.192.1
                                       10.10.0.184 <-- IP of my local machine
                                       10.10.0.1 <-- My router
   NetBIOS over Tcpip. . . . . . . . : Disabled

如果我在 Service Fabric 中运行的代码中执行相同的操作 (System.Diagnostics.Process.Start("ipconfig.exe", "/all");):

Windows IP Configuration

   Host Name . . . . . . . . . . . . : 0ded1f75fa51
   Primary Dns Suffix  . . . . . . . : 
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : Application1

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : XXX
   Description . . . . . . . . . . . : Microsoft Hyper-V Network Adapter
   Physical Address. . . . . . . . . : 00-15-5D-38-E5-2C
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::1d25:4204:2cd4:1bb0%4(Preferred) 
   IPv4 Address. . . . . . . . . . . : 172.20.202.176(Preferred) 
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.20.192.1
   DHCPv6 IAID . . . . . . . . . . . : 67114333
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-23-7C-11-32-00-15-5D-38-E5-2C
   DNS Servers . . . . . . . . . . . : 172.20.192.1
                                       10.10.0.184
   NetBIOS over Tcpip. . . . . . . . : Disabled

您可以看到 10.10.0.1(我的路由器/网关在上次转储中作为 DNS 服务器丢失)。如何添加?

【问题讨论】:

    标签: docker azure-service-fabric hyper-v docker-for-windows azure-service-fabric-mesh


    【解决方案1】:

    你需要在dockerfile的开头添加EXPOSE命令,这是一个已知的bug,即

    FROM .. WORKDIR ... EXPOSE 80

    【讨论】:

      【解决方案2】:

      Windows Containers 1709 中也存在 DNS 问题。您可以尝试使用更新的基础层并重试吗?

      此外,ICMP 在 Azure 中被阻止。 不过,您可以使用 PSPing 来检查连接。

      更多信息here

      因为 ICMP 协议不允许通过 Azure 负载 平衡器,您会注意到您无法从 互联网,并且在 Azure VM 中,您无法 ping 互联网位置。

      【讨论】:

      • 我刚刚尝试过microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1803,但没有成功。 Ping 在 docker 中运行时有效,但在集群中无效:(
      猜你喜欢
      • 2019-11-30
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 2019-10-19
      • 1970-01-01
      • 2019-06-05
      • 2017-08-07
      相关资源
      最近更新 更多