本地Service Fabric网状容器中没有互联网

时间:2018-11-08 21:30:10

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

我正在本地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 cancelToken)      ---内部异常堆栈跟踪的结尾---      在System.Net.Http.ConnectHelper.ConnectAsync(字符串主机,Int32端口,CancellationToken cancelToken)      在System.Threading.Tasks.ValueTask`1.get_Result()      在System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage请求,CancellationToken cancelToken)      在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 cancelledToken)      在System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage请求,CancellationToken cancelToken)      在System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(任务1 sendTask,HttpRequestMessage请求,CancellationTokenSource cts,布尔值disposeCts)处      在System.Net.Http.HttpClient.GetStringAsyncCore(Task`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服务器丢失了)。如何添加呢?

2 个答案:

答案 0 :(得分:1)

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

FROM .. WORKDIR ... EXPOSE 80

答案 1 :(得分:0)

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

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

更多信息here

  

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