首页 > 解决方案 > 无法加载源 https://api.nuget.org/v3/index.json 的服务索引。[C:\app\aspnetapp.csproj]

问题描述

https://github.com/dotnet/dotnet-docker-samples/tree/master/aspnetapp

码头工人命令docker build -t aspnetapp

我收到 docker build 命令的错误

C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): 错误:无法加载源https://api.nuget.org/v3/index.json的服务索引。[C:\app\aspnetapp.csproj]

错误信息截图

[1]PS C:\Users\pssharma\dotnet-docker-samples\aspnetapp> docker build -t aspnetapp .
Sending build context to Docker daemon  2.444MB
Step 1/10 : FROM microsoft/aspnetcore-build:2.0 AS build-env
 ---> eb21d939e0d8
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> d4ec30216ed7
Step 3/10 : COPY *.csproj ./
 ---> Using cache
 ---> 2ff39b5e6cb4
Step 4/10 : RUN dotnet restore
 ---> Running in 776764a35311
  Restoring packages for C:\app\aspnetapp.csproj...
  Restoring packages for C:\app\aspnetapp.csproj...
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\asp
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error :   An error occurred while sending the request. [C:\app\aspnetapp.csproj]
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error :   The operation timed out [C:\app\aspnetapp.csproj]

以下命令返回一个非零代码:1

powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; dotnet restore

错误信息截图

标签: docker

解决方案


当主机存在多个网络适配器并且所述适配器的优先级配置错误时,这似乎会发生。运行以下命令以显示网络适配器表:

Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending

您希望您的主适配器(在我的情况下是 wifi)具有最低的InterfaceMetric。

Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 1

我的网络适配器表供参考: 在此处输入图像描述

有关更多信息,请参阅此 github 线程: https ://github.com/docker/for-win/issues/2760#issuecomment-430889666


推荐阅读