3

I'm trying to run a .NET Core dockerfile but keep getting errors with dotnet restore. I'm running it in a Linux container. I tried running it in a Windows container but got an error during the COPY command.

I have a docker compose file that loads a .NET Core dockerfile from a subfolder. I run 'docker-compose up' in Powershell. The build process gets to the dotnet restore step and throws this error:

/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : Unable to load the service index for source http://192.168.30.2:8080/tfs/DefaultCollection/_packaging/api-library/nuget/v3/index.json. [/Portal.API/Portal.Api.csproj]
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error :   GSSAPI operation failed with error - Unspecified GSS failure.  Minor code may provide more information (SPNEGO cannot find mechanisms to negotiate). [/Portal.API/Portal.Api.csproj]

I tried updating the devenv.exe.config file in Visual Studio based on this Stackoverflow post: https://stackoverflow.com/a/47837720/2026659

After updating devenv.exe.config I got this slightly different error (also included the entire build output):

    Step 1/9 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS api-env
 ---> cef7866e800b
Step 2/9 : WORKDIR /Portal.API
 ---> Using cache
 ---> 80eea76dc2a0
Step 3/9 : COPY ./Portal.API/Portal.Api.csproj .
 ---> Using cache
 ---> 0739924c5ebf
Step 4/9 : COPY ./Portal.API/NuGet.config .
 ---> f1a514456db0
Step 5/9 : RUN dotnet restore
 ---> Running in 9d4a8f5d6239
  Restore completed in 8.15 sec for /Portal.API/Portal.Api.csproj.
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : Unable to load the service index for source http://192.168.30.2:8080/tfs/DefaultCollection/_packaging/api-library/nuget/v3/index.json. [/Portal.API/Portal.Api.csproj]
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error :   Connection refused [/Portal.API/Portal.Api.csproj]
ERROR: Service 'portal.api' failed to build: The command '/bin/sh -c dotnet restore' returned a non-zero code: 1

UPDATE: Some of my NuGet packages are hosted on a private server on a local network which I access via a VPN. I use Windows Active Directory to log in to my work laptop and I think those credentials are used to access the private server.

UPDATE 2: I added login credentials to my NuGet.config like this:

...
<packageSourceCredentials>
    <api-library>
        <add key="Username" value="username" />
        <add key="ClearTextPassword" value="password" />
      </api-library>
  </packageSourceCredentials>
</configuration>

Now I get a different error when running dotnet restore in the docker container:

/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : Unable to load the service index for source http://192.168.30.2:8080/tfs/DefaultCollection/_packaging/api-library/nuget/v3/index.json. [/Portal.API/Portal.Api.csproj]
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error :   GSSAPI operation failed with error - An invalid name was supplied (Configuration file does not specify default realm).

After doing more googling, I think I need to pass login credentials in a different way, possibly with a Personal Access Token like in this GitHub post: https://github.com/microsoft/artifacts-credprovider/issues/63

I'm not sure how to go about it.

5
  • 1
    Does your project rely on NuGet packages hosted by a private nuget server on 192.168.30.2:8080? It looks like nuget is trying to reach that server from inside the container and is unable to. (I'm not a Docker networking whiz, so I'm not sure if that's expected or not) Commented Jan 3, 2020 at 22:20
  • 1
    It says connection refused, so it's not a problem of reaching from inside the container. From anywhere he connects to it, there is nothing listening on port 8080 of 192.168.30.2. You can confirm it with a telnet 192.168.30.2 8080. Commented Jan 3, 2020 at 22:26
  • Yes , it's a private server hosted on my work's local network. I access it via a VPN.
    – mdailey77
    Commented Jan 4, 2020 at 19:29
  • @mdailey77 I am also trying to handle same situation .Has anything worked for you?
    – Iquery
    Commented Jun 3, 2020 at 8:17
  • @lquery I forgot about this question. I switched to Windows container and dotnet restore worked.
    – mdailey77
    Commented Jun 3, 2020 at 13:05

3 Answers 3

2

had so many issues with this. Just figured out, dotnet restore is trying to use NTML and you need to force it to use basic auth for the PAT to work on linux. based on this post https://developercommunity.visualstudio.com/t/azure-artifacts-nuget-feed-gives-error-during-rest/711941

in the you need to add

  <add key="ValidAuthenticationTypes" value="basic" />

ex:

<packageSourceCredentials>
    <api-library>
        <add key="Username" value="username" />
        <add key="ClearTextPassword" value="password" />
        <add key="ValidAuthenticationTypes" value="basic" />
      </api-library>
  </packageSourceCredentials>
</configuration>
1

@greektreat; Thank you! this solved an issue I was struggling with for days. During a docker build my private feed timeout. Adding the basic authentication solved my issue.

fyi my updated docker file statement; RUN dotnet nuget add source "$feed" -n PrivateFeed -u docker -p "$pat" --store-password-in-clear-text --valid-authentication-types "basic" --configfile nuget.config

0

I was able to solve the issue by using a Windows container.

1
  • Have tried using Linux containers again? I am having the same issue and I don't want to use Windows.
    – greektreat
    Commented Aug 25, 2021 at 18:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.