Docker nuget connection timeout

Jan*_*ník 12 routing timeout kubernetes

Trying to utilize official jetbrains\teamcity-agent image on Kubernetes. I've managed to run Docker in Docker there but trying to build an ASP.NET Core image with docker build command failes on dotnet restore with

The HTTP request to 'GET https://api.nuget.org/v3/index.json' has timed out after 100000ms.

When I connect to the pod itself and try curling the URL it's super fast. So I assume network is not an issue. Thank for any advice.

Update

Trying to run a simple dotnet restore step from container worked. But not from inside the docker build.

Update 2

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

docker build使用此Dockerfile运行简单:

FROM praqma/network-multitool AS build
RUN route
RUN ping -c 4 google.com
Run Code Online (Sandbox Code Playgroud)

产生输出:

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
Run Code Online (Sandbox Code Playgroud)

Kubernetes编排的Pod可以正常上网。我使用 Calico 作为网络层。

小智 13

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

运行 dotnet restore --disable-parallel


Wel*_*ing 5

就我而言,解决方案已在此处标记

正如评论中所述,“因此,微软可能需要通过更改 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>
Run Code Online (Sandbox Code Playgroud)


Ana*_*sky 4

我有完全相同的行为:我有一个包含几个 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
Run Code Online (Sandbox Code Playgroud)

我通常可以从 docker 容器从 nuget.org 执行 ping 操作并卷曲页面。

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

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

更新2好吧,现在我能理解任何事情了。我尝试执行

curl https://api.nuget.org/v3/index.json 
Run Code Online (Sandbox Code Playgroud)

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

之后我尝试跑步

wget https://api.nuget.org/v3-flatcontainer/system.threading/4.0.11/system.threading.4.0.11.nupkg
Run Code Online (Sandbox Code Playgroud)

并且包下载成功

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

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

docker run -it -v d:/project/test:/mnt/proj teamcity-agent-core3.1 bash
Run Code Online (Sandbox Code Playgroud)

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

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

dotnet restore test.sln
Run Code Online (Sandbox Code Playgroud)

失败并显示以下消息:

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.
Run Code Online (Sandbox Code Playgroud)