c# - 使用 Windows 容器在 Docker Desktop 中运行 ASP.NET 时,传出 HTTP 请求超时

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

我第一次在 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 请求。

我收到以下错误消息:

'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'



在 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

测试网络连接-端口 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 捕获:
Successful connection test

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

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

最佳答案

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

关于c# - 使用 Windows 容器在 Docker Desktop 中运行 ASP.NET 时,传出 HTTP 请求超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56148895/

相关文章:

docker - 热重载无法在带有 golang 的 docker 中工作 (github.com/cosmtrek/air)

java - 我的java代码经常陷入循环 "while ((line = rd.readLine()) != null) {"。如何优化代码

c# - 报告框架背后的基本原理

c# - 如何从数据表中删除空行

docker - 在nfs挂载上运行的Docker导致无法复制和无法穿梭

c - 套接字编程在C中用循环发送和接收消息

networking - 我可以在受控环境中忽略 UDP 缺乏可靠性功能吗?

c# - 生成动态流程图

c# - 未知服务器标记 'cc1:AsyncFileUpload'

java - 从 docker 镜像运行 Maven 命令