【问题标题】:Docker nuget connection timeoutDocker nuget 连接超时
【发布时间】:2021-05-05 20:52:56
【问题描述】:

尝试在 Kubernetes 上使用官方 jetbrains\teamcity-agent 镜像。我已经设法在 Docker 中运行 Docker,但尝试使用 docker build 命令构建 ASP.NET Core 映像在 dotnet restore 上失败

对“GET https://api.nuget.org/v3/index.json”的 HTTP 请求在 100000 毫秒后超时。

当我连接到 pod 本身并尝试curling URL 时,它的速度非常快。所以我认为网络不是问题。感谢您的建议。

更新

尝试从容器运行一个简单的dotnet restore 步骤。但不是来自docker build

更新 2

我已经隔离了这个问题,它与 nuget 或 TeamCity 无关。是否与 Kubernetes 主机上的网络相关。

使用这个Dockerfile运行简单的docker build

FROM praqma/network-multitool AS build
RUN route
RUN ping -c 4 google.com

产生输出:

Step 1/3 : FROM praqma/network-multitool AS build
 ---> 3619cb81e582
Step 2/3 : RUN route
 ---> Running in 80bda13a9860
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         172.17.0.1      0.0.0.0         UG    0      0        0 eth0
172.17.0.0      *               255.255.0.0     U     0      0        0 eth0
Removing intermediate container 80bda13a9860
 ---> d79e864eafaf
Step 3/3 : RUN ping -c 4 google.com
 ---> Running in 76354a92a413
PING google.com (216.58.201.110) 56(84) bytes of data.

--- google.com ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 53ms

Kubernetes 编排的 Pod 可以正常访问互联网。我使用 Calico 作为网络层。

【问题讨论】:

标签: kubernetes routing timeout


【解决方案1】:

我通过将参数 --disable-parallel 传递给 restore 命令来解决此问题,该命令禁用并行恢复多个项目。

运行 dotnet restore --disable-parallel

【讨论】:

  • 不知何故,这个解决方案成功地在 jenkins docker 中构建了 dotnet 核心映像
  • 谢谢!它也为我解决了问题(本地 docker build - Ubuntu 20.04.1 LTS 和 Docker 20.10.1)
【解决方案2】:

我的行为完全相同: 我有包含几个 nuget 依赖项的解决方案 它在本地机器上构建没有任何问题。 它在 Windows 构建代理上构建没有任何问题 它在 docker 主机上构建没有任何问题 但后来我尝试在 docker 的构建代理中构建它 - 我有很多消息如下:

Failed to download package 'System.Threading.4.0.11' from 'https://api.nuget.org/v3-flatcontainer/system.threading/4.0.11/system.threading.4.0.11.nupkg'.
  The download of 'https://api.nuget.org/v3-flatcontainer/system.threading/4.0.11/system.threading.4.0.11.nupkg' timed out because no data was received for 60000ms

我可以正常地从 docker 容器 ping 和 curl 来自 nuget.org 的页面。

所以我认为这是一些特殊情况。我找到了一些关于 MTU 的信息,但我没有对其进行测试。

更新最初的问题可能是连接到 k8s - 我的容器在基于 ubuntu 18.04 和 flannel ang k8s v1.16 的 k8s 集群中工作 在我的本地机器(基于win)上,所有工作都没有任何问题......但这很奇怪,因为我有许多服务可以在这个集群中正常工作,没有任何问题! (如harbor、graylog、jaeger等)

UPDATE 2 好的,现在我什么都能理解了。 我尝试执行

curl https://api.nuget.org/v3/index.json 

并且可以毫无错误地获取文件内容

之后我尝试运行

wget https://api.nuget.org/v3-flatcontainer/system.threading/4.0.11/system.threading.4.0.11.nupkg

包下载成功

但在我运行 dotnet restore 后,我仍然收到超时错误

更新 3 我尝试不是在 k8s 集群中而是在本地的 docker 中重现问题 我运行容器

docker run -it -v d:/project/test:/mnt/proj teamcity-agent-core3.1 bash

teamcity-buildagent-core3.1 - 我的镜像基于 jetbrains/teamcity-agent,其中包含 .net core 3.1 sdk。

然后在交互式会话中执行命令:

dotnet restore test.sln

失败并显示以下消息:

Failed to download package 'System.Runtime.InteropServices.4.3.0' from 'https://api.nuget.org/v3-flatcontainer/system.runtime.interopservices/4.3.0/system.runtime.interopservices.4.3.0.nupkg'.
   Received an unexpected EOF or 0 bytes from the transport stream.
  The download of 'https://api.nuget.org/v3-flatcontainer/system.text.encoding.extensions/4.3.0/system.text.encoding.extensions.4.3.0.nupkg' timed out because no data was received for 60000ms.
    Exception of type 'System.TimeoutException' was thrown.

【讨论】:

  • 我尝试在 /etc/docker/daemon.json 中将 MTU 设置为 1460。仍然是相同的行为。
【解决方案3】:

我遇到了类似的问题。我犯的错误是没有在 docker 映像上指定确切的 dotnet 版本。

FROM mcr.microsoft.com/dotnet/core/sdk AS build

我的项目针对 dotnet 2.2。我不知道这是拉最新的 dotnet SDK 3.1。所以当 dotnet restore 运行时,它会超时。

这就是我所做的。

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build

我必须指定一个特定的版本。我不确定这是否与您的问题有关,但我希望它能让您朝着正确的方向前进。始终明确使用图像版本。

【讨论】:

  • 好一个........我也没有提到docker 2.2 sdk版本
【解决方案4】:

在我的情况下,解决方案被标记为here

如评论中所述,“因此,微软可能需要通过更改 mcr.microsoft.com/dotnet/sdk:5.0 中的默认 nuget.config 来解决此问题。”

这是我的问题。从 sdk:5.0 构建 Docker。解决方案似乎在做这项工作,就是在解决方案的根目录下添加一个 nuget.config 文件。

nuget.config 的内容(同样来自该问题的帖子):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key='maxHttpRequestsPerSource' value='10' />
  </config>
</configuration>

【讨论】:

    【解决方案5】:

    当我使用来自 gitlab-runner (docker) 的 docker 容器中的构建时,我遇到了类似的 @NIMROD MAINA 和 @Anatoly Kryzhanovsky 问题。

    当我在 docker 容器外运行 dotnet restore 时。一切正常!

    【讨论】:

    • 对于 GitLab,他们的跟踪器上已经有一个很长的 issue 可能会对您有所帮助。但处于低优先级路线图上。
    【解决方案6】:

    检查您的 DNS 设置(A 记录)。尝试输入nslookup yourfeeddomain。确保 IP 地址为 1 且已解析。

    【讨论】:

      猜你喜欢
      • 2015-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      相关资源
      最近更新 更多