Search code examples
linuxdockerdockerfilenugetdocker-desktop

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


I'm trying to restore nuget packages in a linux docker container using this simple dockerfile:

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

with this command using the command prompt on 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 .

which results in this error:

[+] 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

What am I missing?


Solution

  • This issue was caused by our proxy. Our infrastructure team had to explicitly allow the api.nuget.org URL. The error message seems to be missleading.