dotnet restore with private nuget server fails in docker-compose

618 Views Asked by At

The dotnet restore step is failing only from docker-compose, and only when I use a private nuget server in addition to the public server. It seems to be looking on my private server for public packages, and then it times out. I get this error:

#15 101.5   The HTTP request to 'GET http://my-nuget/Shared/nuget/FindPackagesById()?id='Microsoft.EntityFrameworkCore.Design'&semVerLevel=2.0.0' has timed out after 100000ms.

I don't have the problem when I run dotnet restore manually, without it being in docker. I have the problem on two projects that both use the private and public nuget servers. Another project only uses the public server, and it works with no problem (and it does not have a nuget.config).

My nuget.config is:

<configuration>
    <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
        <add key="USAS" value="http://my-nuget/Shared/nuget" />
    </packageSources>
</configuration>

If I remove my private server, I get errors for the three packages that use the private server, but I don't get the errors for the public packages.

2

There are 2 best solutions below

0
On

Add the private server url after dotnet restore in your Dockerfile, may look like below:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
...

RUN dotnet restore "Application.csproj" -s "YOUR PRIVATE NUGET SERVER URL"
...

0
On

Try to remove docker networks. In my case it helped.
docker network prune - Remove all unused networks