c# - 使用 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”立即生效。
我看到故障计算机正在使用相同的 DNS 服务器来查找“internetbeacon.msedge.net”的 IP,但是在 IP 13.107.4.52 的响应之后,没有记录来自容器的 TCP 请求。在工作机器上,此请求在 DNS 响应之后立即被捕获。
解决方案
检查主机防火墙/AV,因为它很可能是这里的 curlpit
推荐阅读
- java - 带有 MenuBar 的摇摆 JFrame 上的阴影
- android - 错误:找不到符号 private final java.util.List
我的数据 - amazon-web-services - docker pull 适用于 GitLab 容器注册表中除 AWS EC2 之外的所有机器
- java - 我正在尝试删除特定节点(节点 3)的数据但它不起作用,我需要知道我的代码中的错误在哪里
- python - 使用(Python,Selenium)在 ProtonMail 上自动创建电子邮件
- keycloak - 用户管理访问 (uma) 是否涵盖行级安全性
- python - 在循环中将列表添加到字典仅添加最后一个列表
- javascript - TypeError:无法读取未定义的属性'then' - React Hooks
- recharts - Recharts堆栈条形图半径问题
- python - Selenium WebDriverWait 不抛出超时异常