无法加载源https://api.nuget.org/v3/index.json的服务索引.[C:\应用\ aspnetapp.csproj]

Pav*_*rma 19 docker

https://github.com/dotnet/dotnet-docker-samples/tree/master/aspnetapp Docker命令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:\应用\ 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]
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; dotnet restore' returned a non-zero code: 1[enter image description here][2]
Run Code Online (Sandbox Code Playgroud)

Pon*_*ian 20

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

Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
Run Code Online (Sandbox Code Playgroud)

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

Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 1
Run Code Online (Sandbox Code Playgroud)

我的网卡表供参考: 在此处输入图片说明

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


小智 13

对我来说,这个问题随机出现(以及多个类似的问题,例如"权限被拒绝为nuget"等.要解决此问题,请重新启动Visual Studio)对于Windows,它通过重新启动docker服务并重新启动Visual Studio(2017)来修复.

  1. 关闭Docker和Visual Studio
  2. Winkey + R,输入services.msc
  3. 找到Docker for Windows Service并重新启动它(通常重启Docker是不够的)
  4. 启动Docker和Visual Studio


Ilk*_*lko 6

只需添加--network=host选项docker build

docker build -t aspnetapp . --network=host


pat*_*ley 5

我通过从命令行传入docker build环境变量来实现此目的,如下所示:

docker build --build-arg HTTP_PROXY=http://{un}:{pw}@{proxyhost}:{port} --build-arg HTTPS_PROXY=http://{un}:{pw}@{proxyhost}:{port} -t aspnetapp

*请注意,您的用户名必须使用网址编码(例如DOMAIN \ name => DOMAIN%5Cname)


Gab*_*aro 3

遇到了同样的问题,问题是缺少使用的依赖项NuGet

我正在使用该microsoft/dotnet:sdk映像,安装到我的映像后它就可以工作了libcurl3

在恢复之前尝试添加 RUN apt-get update && apt-get install -y libcurl3 到您的。Dockerfile

如果不起作用,请尝试重新启动 Docker 实例。

edit:如果这对您没有帮助,那么有些人正在尝试解决同样的问题,这是一个悬而未决的问题。NuGet github

edit2:添加了 Ignas 解决方案:重新启动 docker 实例。

  • 在答案中引用的 GitHub 问题中找到 - 需要重新启动我的 Docker 实例。 (2认同)