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

时间:2018-04-26 09:21:55

标签: 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):错误:无法加载源{{3}的服务索引}。 [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]

14 个答案:

答案 0 :(得分:10)

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

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

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

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

我的网络适配器表供参考: enter image description here

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

答案 1 :(得分:9)

对我来说,这个问题是随机出现的(连同多个类似的问题,例如“对nuget拒绝的权限”等。要解决此问题,请重新启动Visual Studio) 对于 windows ,通过重新启动docker服务并重新启动Visual Studio(2017)来修复它。

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

答案 2 :(得分:3)

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

docker build -t aspnetapp . --network=host

答案 3 :(得分:2)

出现同样的问题,问题是NuGet使用的依赖项缺失。

我正在使用microsoft/dotnet:sdk图片,并且在将libcurl3安装到我的图片后就可以了。

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

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

edit:如果这对您没有帮助,NuGet github上有this open issue,其中有些人正试图解决同样的问题。

edit2:添加了Ignas解决方案:重启docker instance。

答案 4 :(得分:1)

我是通过从命令行传入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)

答案 5 :(得分:1)

就我而言,在Dockerfile中,我有

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2

但是我只安装了.net 2.1(通过dotnet --list-sdks查看)。因此,我必须将2.2更改为2.1才能使其正常工作。

答案 6 :(得分:1)

我很惊讶没有人这么说。这是由于未安装最新的SDK引起的。就我而言,码头工人正在寻找文件

C:\ Program Files \ dotnet \ sdk \ 3.1.302 \ NuGet.targets

但是我的计算机上不存在该文件,而是使用了其他次要版本。

C:\ Program Files \ dotnet \ sdk \ 3.1.301 \ NuGet.targets

我确定他们已经可以使用较旧的版本了,但就我而言,我只是更新了下载的最新sdk

答案 7 :(得分:0)

打开CMD或Powershell并运行: dotnet nuget locals http-cache --clear

https://status.nuget.org/

答案 8 :(得分:0)

我在Debian 9上遇到了同样的问题。我断言了与本地网络断开连接的错误。它对我有用,因为我没有在代码库上进行任何更改,也不需要从nuget获取软件包。

答案 9 :(得分:0)

我通过禁用Avast Antivirus并卸载了McAffee Antivirus在Windows 10计算机上解决了此问题。

  • 右键单击“通知”标签中的Avast图标
  • 选择Avast Shields控件
  • 单击“在重新启动计算机之前禁用”。

现在您可以成功运行Docker Build。 如果需要,我可以提供进一步的帮助。

答案 10 :(得分:0)

与代理人奋战一小时后,终于可以采用以下解决方案了:

docker build --build-arg HTTP_PROXY=http://xxxx.com:8080 --build-arg HTTPS_PROXY=http://yyyy:8080 -t kdekarin/aspnet .

有关更多信息,请参见@patrickbadley的评论!

答案 11 :(得分:0)

如果此问题是由组织的自签名证书引起的,则可以通过以下方法解决此问题:

  1. 获取您的IT部门提供的证书文件(* .cer)。
  2. 将其复制到SSL证书位置:<string name="appLabel">My Awesome App</string>
  3. 更新SSL证书列表:app/src/prod/res/values/string.xml

(对Ubuntu有效,对其他Linux发行版相似的步骤)。

答案 12 :(得分:0)

发生这种情况的另一个原因。如果您的docker文件定位到Windows容器,而您的docker正在运行linux模式,反之亦然。

答案 13 :(得分:-1)

@patrickbadley的解决方案对我有用。

  

我通过传入docker build环境变量来完成这项工作   从命令行开始,如下所示:

     

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