问题描述:
使用官方镜像 mcr.microsoft.com/dotnet/sdk:5.0 AS build,在docker build 过程中报错:
Step 15/24 : RUN dotnet build "Project.API.csproj" -c Release -o /app/build
---> Running in 2b1b267b12c8
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
/usr/share/dotnet/sdk/5.0.408/NuGet.targets(131,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/src/Project.API/Project.API.csproj]
/usr/share/dotnet/sdk/5.0.408/NuGet.targets(131,5): error : The HTTP request to 'GET https://api.nuget.org/v3/index.json' has timed out after 100000ms. [/src/Project.API/Project.API.csproj]
Build FAILED.
/usr/share/dotnet/sdk/5.0.408/NuGet.targets(131,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/src/Project.API/Project.API.csproj]
/usr/share/dotnet/sdk/5.0.408/NuGet.targets(131,5): error : The HTTP request to 'GET https://api.nuget.org/v3/index.json' has timed out after 100000ms. [/src/Project.API/Project.API.csproj]
0 Warning(s)
1 Error(s)
解决方法:
浏览器中直接访问 https://api.nuget.org/v3/index.json 无响应,nslookup 解析改域名的 IP为 23.101.10.141,是香港微软云地址,估计是被墙了。。。
https://www.itdog.cn/ping/api.nuget.org
使用多地ping测试,发现中国大陆地区都解析到了23.101.10.141,且响应均为超时。尝试在ci/cd的节点(node3)上添加hosts,将api.nuget.org域名指向海外IP(152.199.40.167)后,问题解决!
❗❗❗补充说明:
上述方法只是临时解决之道,api.nuget.org 的cdn地址会变,当多地ping测试解析的国内IP恢复正常后,强烈建议把hosts记录去除!