首页 > 解决方案 > 使用私有 nuget 服务器的 dotnet restore 在 docker-compose 中失败

问题描述

dotnet restore步骤仅从 docker-compose 失败,并且仅当我使用除公共服务器之外的私有 nuget 服务器时。它似乎在我的私人服务器上寻找公共包,然后超时。我收到此错误:

#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.

当我手动运行 dotnet restore 时,我没有问题,而它没有在 docker 中。我在两个都使用私有和公共 nuget 服务器的项目上遇到了问题。另一个项目只使用公共服务器,并且没有问题(并且它没有 nuget.config)。

我的 nuget.config 是:

<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>

如果我删除了我的私有服务器,我会收到使用私有服务器的三个包的错误,但我不会收到公共包的错误。

标签: dockerdocker-composenuget-packagedotnet-restore

解决方案


在 Dockerfile 中添加私有服务器 url dotnet restore,如下所示:

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

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


推荐阅读