【问题标题】:Dotnet Restore fails in docker builddocker build 中的 Dotnet 还原失败
【发布时间】:2018-12-10 11:37:51
【问题描述】:

您好,我正在尝试 dockerize ASP NET Core 2.1 应用程序,而 docker build 在执行 dotnet restore 时失败。 我已经检查了其他线程是否存在此特定问题
Nuget connection attempt failed "Unable to load the service index for source"

那里提供的解决方案对我没有帮助。

Dockerfile

ARG serverPath=./Core/Server

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app


COPY ./Core/Server/*.csproj ./
RUN dotnet restore  //fails here

COPY ./Core/Server/ ./
RUN dotnet publish -c Release -o out  


FROM microsoft/dotnet:2.1-aspnetcore-runtime 
WORKDIR /app
COPY --from=build-env /app/out  .
ENTRYPOINT ["dotnet","Server.dll"]

docker build 的输出

$ docker build -t server .
Sending build context to Docker daemon  11.13MB
Step 1/11 : ARG serverPath=./Core/Server
Step 2/11 : FROM microsoft/dotnet:sdk AS build-env
 ---> 343e2dc38168
Step 3/11 : WORKDIR /app
 ---> Using cache
 ---> e9b75480ecb9
Step 4/11 : COPY ./Core/Server/*.csproj ./
 ---> Using cache
 ---> 2de864bedf6a
Step 5/11 : RUN dotnet restore 
 ---> Running in 2fc6963e7e2c
  Restoring packages for /app/Server.csproj...
/usr/share/dotnet/sdk/2.2.100/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/app/Server.csproj]
/usr/share/dotnet/sdk/2.2.100/NuGet.targets(114,5): error :   The SSL connection could not be established, see inner exception. [/app/Server.csproj]
/usr/share/dotnet/sdk/2.2.100/NuGet.targets(114,5): error :   Authentication failed because the remote party has closed the transport stream. [/app/Server.csproj]
The command '/bin/sh -c dotnet restore -p:RestoreUseSkipNonexistentTargets=false -nowarn:msb3202,nu1503' returned a non-zero code: 1

【问题讨论】:

  • 我遇到了同样的问题,但使用的是 .NET Core 2.2 Windows 映像。我也经历了另一个线程但没有成功。一件奇怪的事情是我可以在 Visual Studio 2017 之外运行 Docker。我只有命令行中的 Nuget 连接问题(即使以管理员身份运行)。
  • 我也有类似的问题。根据关于此线程 github.com/NuGet/Home/issues/6742 的讨论,我似乎更成功地将 --disable-parallel 选项添加到 dotnet restore。

标签: docker nuget dotnet-restore


【解决方案1】:

试试这个

docker network ls

这应该列出网络 ID 尝试运行 docker build

docker build --network=<networkid> tag=<tag>

在列出的所有网络上尝试上述方法,它可以与一个网络一起使用,即主机网络。

【讨论】:

  • 这是我面对这个烦人的“nuget restore”网络错误时唯一有效的解决方案。谢谢!
  • 我正在从 WSL2 (Ubuntu 20.04.3 LTS) 运行 docker build,在尝试了所有出现在 docker network ls 中的网络之后,它仍然无法与其中任何一个一起使用.一些会立即超时,而另一些则需要一段时间。
  • 原来我的问题是由于我的 DNS 在我的 WSL2 中不太正确。在下面发布另一个答案...
【解决方案2】:

尝试将您的 DNS 服务器更新为固定(默认应为 8.8.8.8)。

我在设置-> 网络-> DNS 服务器中找到了这个

【讨论】:

    【解决方案3】:

    如果在 Windows 7 或 Windows Server 2008 R2 上,启用 TLS 1.2 以与新的 NuGet 服务器通信。 Microsoft DevBlogs on NuGet TLS status

    【解决方案4】:

    我在尝试在我的 Windows 机器上运行的 WSL2 (Ubuntu 20.04) 中构建 docker 映像时遇到了同样的错误。

    在我的情况下,我确认我可以从我的 WSL2 中使用 nuget:

    curl -v https://api.nuget.org/v3/index.json
    

    但是,如果我尝试来自 Docker 容器的相同请求,它无法解析主机名(这只会挂起):

    docker run -it --rm curlimages/curl -v -k https://api.nuget.org/v3/index.json
    

    所以这指出了 DNS 的问题,并且由于 Docker 使用您的“主机”DNS 配置,我专注于我的 WSL2 DNS。我使用的是 WSL2 使用的默认 DNS。这意味着/etc/resolv.conf 是自动生成的...我按照此处的说明将其关闭:https://superuser.com/questions/1533291/how-do-i-change-the-dns-settings-for-wsl2

    我随后在/etc/resolv.conf 中手动配置的 DNS 是我公司的内部 DNS 服务器。重启 WSL2 和 Docker 后,我能够在 Docker 容器中解析 api.nuget.org。

    【讨论】:

      猜你喜欢
      • 2020-09-07
      • 2020-07-12
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      相关资源
      最近更新 更多