首页 > 解决方案 > 使用 Windows 容器在 Docker Desktop 中运行 ASP.NET 时,传出 HTTP 请求超时

问题描述

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

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 timeouts中的建议设置 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 响应之后立即被捕获。

标签: c#dockernetwork-programmingdocker-for-windows

解决方案


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


推荐阅读