【问题标题】:Outgoing HTTP requests time out when running ASP.NET in Docker Desktop using Windows Container使用 Windows 容器在 Docker Desktop 中运行 ASP.NET 时,传出 HTTP 请求超时
【发布时间】:2019-10-02 13:42:52
【问题描述】:

我第一次在 Docker Desktop 中运行 ASP.NET Web 应用程序。我使用 Visual Studio 2019 中的标准模板创建了一个 ASP.NET 应用程序(针对 .NET Framework),并支持 Docker。

Dockerfile:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-1803
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .

Docker-compose.yml:

version: '3.4'

services:
  mydockerizedwebapp:
    image: ${DOCKER_REGISTRY-}mydockerizedwebapp
    container_name: mydockerizedwebapp
    build:
      context: .\MyDockerizedWebApp
      dockerfile: Dockerfile

Docker-compose.override.yml:

version: '3.4'

services:
  mydockerizedwebapp:
    ports:
      - "80"
networks:
  default:
    external:
      name: nat

我已经在我的 Win 10 计算机(运行 Windows 容器)上安装了 Docker Desktop。

问题是我无法从 Docker 内的 Web 服务器发出传出 http 请求。

我收到以下错误消息:

'连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接建立失败,因为连接的主机没有响应'

在 IIS Express 中运行网络服务器可以正常工作。

我已使用 Powershell 连接到托管图像的容器。运行“Test-NetConnection”会返回以下输出:

PS C:\inetpub\wwwroot> Test-NetConnection


ComputerName           : internetbeacon.msedge.net
RemoteAddress          : 13.107.4.52
InterfaceAlias         : Ethernet
SourceAddress          : 172.24.21.136
PingSucceeded          : True
PingReplyDetails (RTT) : 14 ms

Test-NetConnection -port 80 在一段时间后失败,输出如下:

PS C:\inetpub\wwwroot> Test-NetConnection -port 80
WARNING: TCP connect to (13.107.4.52 : 80) failed


ComputerName           : internetbeacon.msedge.net
RemoteAddress          : 13.107.4.52
RemotePort             : 80
InterfaceAlias         : Ethernet
SourceAddress          : 172.24.21.136
PingSucceeded          : True
PingReplyDetails (RTT) : 15 ms
TcpTestSucceeded       : False

如果我在同一个容器中打开不同的 powershell 窗口并运行“netstat -an”以查看活动连接,则 TCP 请求是可见的:

Active Connections

  Proto  Local Address          Foreign Address        State
[...]
  TCP    172.24.21.136:49169    13.107.4.52:80         SYN_SENT

在整个连接测试期间,状态为“SYN_SENT”。

我已尝试按照Docker - Outgoing HTTPS requests timing out 中的建议设置 MTU,但它对我不起作用。

值得一提的是,我是在远程工作,所以我有VPN连接(软件),但是即使断开VPN也无法使用。

我错过了什么吗? 我尝试使用 nanoserver 映像创建 ASP.NET Core Web 应用程序,但问题仍然存在。所以我认为问题一定出在我的 Docker/网络配置上?

更新:

我测试了在另一台既没有 VPN 连接也没有安装相同 AV 的计算机上运行相同的图像。 “Test-NetConnection -port 80”立即生效。

这是在不同计算机上成功测试的 Wireshark 捕获:

这是 Wireshark 在我的计算机上捕获的失败测试:

我看到故障计算机正在使用相同的 DNS 服务器来查找“internetbeacon.msedge.net”的 IP,但是在 IP 13.107.4.52 的响应之后,没有记录来自容器的 TCP 请求。在工作机器上,此请求在 DNS 响应之后立即被捕获。

【问题讨论】:

  • 检查主机上的防火墙并尝试使用另一台计算机。这很可能是由您主机上的防火墙/AV 引起的
  • 我不认为这是我主机上的防火墙问题,因为“Test-NetConnection -port 80”在主机上有效。但是,我有一个可能是问题的 AV。我将在没有 AV 的另一台计算机上尝试。
  • @GregorySuvalian 我现在在我的赛门铁克流量日志中发现它阻止了请求。我现在已经向网络管理员提出了这个问题。

标签: c# docker network-programming docker-for-windows


【解决方案1】:

检查主机防火墙/AV,因为这里很可能是 curlpit

【讨论】:

  • 我卸载了 Symantec Endpoint Protection,现在可以从 docker 容器进行外部 Web 调用!
猜你喜欢
  • 2019-09-17
  • 1970-01-01
  • 2020-04-24
  • 2021-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-06
  • 1970-01-01
相关资源
最近更新 更多