如何使用代理恢复 docker 容器中的 nuget 包?

How to restore nuget packages in a docker container using a proxy?

我正在尝试使用这个简单的 docker 文件在 linux docker 容器中恢复 nuget 包:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

使用此命令在 windows 上使用命令提示符:

docker build --build-arg HTTP_PROXY=http://172.1.0.15:8080 --build-arg HTTPS_PROXY=http://172.1.0.15:8080 --no-cache -t test -f Dockerfile .

导致此错误:

[+] Building 1.7s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.1s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.1s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0                                                  0.2s
 => [1/4] FROM mcr.microsoft.com/dotnet/sdk:5.0@sha256:b2f3f15ee6100efdd36819a429b75d936e4be71bb2487cc48223554f08  0.0s
 => [internal] load build context                                                                                  0.1s
 => => transferring context: 4.17kB                                                                                0.0s
 => CACHED [2/4] WORKDIR /app                                                                                      0.0s
 => [3/4] COPY *.csproj ./                                                                                         0.1s
 => ERROR [4/4] RUN dotnet restore                                                                                 1.2s
------
 > [4/4] RUN dotnet restore:
#7 0.961   Determining projects to restore...
#7 1.162 /usr/share/dotnet/sdk/5.0.403/NuGet.targets(131,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/app/Test.csproj]
#7 1.162 /usr/share/dotnet/sdk/5.0.403/NuGet.targets(131,5): error :   GSSAPI operation failed with error - Unspecified GSS failure.  Minor code may provide more information (SPNEGO cannot find mechanisms to negotiate). [/app/Test.csproj]
------
executor failed running [/bin/sh -c dotnet restore]: exit code: 1

我错过了什么?

这个问题是由我们的代理引起的。我们的基础架构团队必须明确允许 api.nuget.org URL。 错误信息似乎有误导性。