我有相同的问题。我怀疑这与背后的代理有关。
我的 Dockerfile 是:

FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.sln ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "salesorder.qry.webapiapp.dll"]

我在使用 dotnet 发布的步骤中遇到错误:
$ docker build -t salesorder.qry.webapiapp .
Sending build context to Docker daemon  126.1MB
Step 1/10 : FROM microsoft/aspnetcore-build:2.0 AS build-env
 ---> 07590dec9c1e
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> 26007abaa8b5
Step 3/10 : COPY *.sln ./
 ---> Using cache
 ---> 69dc09df88f0
Step 4/10 : RUN dotnet restore
 ---> Using cache
 ---> 7c10e448f636
Step 5/10 : COPY . ./
 ---> Using cache
 ---> c588d98eb49b
Step 6/10 : RUN dotnet publish -c Release -o out
 ---> Running in 9492a4f61e38
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for /app/SalesOrder.Cmd.Application.Model.Events/SalesOrder.Cmd.Application.Model.Events.csproj...
  Restoring packages for /app/SalesOrder.Cmd.Application.Model/SalesOrder.Cmd.Application.Model.csproj...
/usr/share/dotnet/sdk/2.1.200/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/app/SalesOrder.Qry.sln]
/usr/share/dotnet/sdk/2.1.200/NuGet.targets(114,5): error :   An error occurred while sending the request. [/app/SalesOrder.Qry.sln]
/usr/share/dotnet/sdk/2.1.200/NuGet.targets(114,5): error :   SSL connect error [/app/SalesOrder.Qry.sln]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1

但是,如果我直接运行完全相同的指令,则不会出现该错误:
$ dotnet publish -c Release -o out
Microsoft (R) Build Engine version 15.6.84.34536 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 43,43 ms for C:\src\SalesOrder.QueryService\SalesOrder.Cmd.Application.Model\SalesOrder.Cmd.Application.Model.csproj.
  Restore completed in 43,43 ms for C:\src\SalesOrder.QueryService\SalesOrder.Cmd.Application.Model.Events\SalesOrder.Cmd.Application.Model.Events.csproj.
  Restore completed in 4,67 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.Infra.InMemoryRepository\SalesOrder.Qry.Infra.InMemoryRepository.csproj.
  Restore completed in 46,18 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.Application.UnitTests\SalesOrder.Qry.Application.UnitTests.csproj.
  Restore completed in 51,08 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApi.UnitTests\SalesOrder.Qry.WebApi.UnitTests.csproj.
  Restore completed in 32,46 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApiApp\SalesOrder.Qry.WebApiApp.csproj.
  Restore completed in 12,53 ms for C:\src\SalesOrder.QueryService\ToolBelt.Hateoas\ToolBelt.Hateoas.csproj.
  Restore completed in 13,54 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApi\SalesOrder.Qry.WebApi.csproj.
  Restore completed in 2,16 ms for C:\src\SalesOrder.QueryService\ToolBelt.Mapping.Contracts\ToolBelt.Mapping.Contracts.csproj.
  Restore completed in 1,97 ms for C:\src\SalesOrder.QueryService\ToolBelt.Tests.Extensions\ToolBelt.Tests.Extensions.csproj.
  Restore completed in 55,52 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApiApp\SalesOrder.Qry.WebApiApp.csproj.
  Restore completed in 64,69 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.Application.UnitTests\SalesOrder.Qry.Application.UnitTests.csproj.
  Restore completed in 2,36 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.Domain.EventContracts\SalesOrder.Qry.Domain.EventContracts.csproj.
  Restore completed in 2,87 ms for C:\src\SalesOrder.QueryService\SalesOrder.Qry.Application\SalesOrder.Qry.Application.csproj.
  SalesOrder.Cmd.Application.Model -> C:\src\SalesOrder.QueryService\SalesOrder.Cmd.Application.Model\bin\Release\netstandard2.0\SalesOrder.Cmd.Application.Model.dll
  ToolBelt.Tests.Extensions -> C:\src\SalesOrder.QueryService\ToolBelt.Tests.Extensions\bin\Release\netstandard2.0\ToolBelt.Tests.Extensions.dll
  ToolBelt.Mapping.Contracts -> C:\src\SalesOrder.QueryService\ToolBelt.Mapping.Contracts\bin\Release\netstandard2.0\ToolBelt.Mapping.Contracts.dll
  ToolBelt.Tests.Extensions -> C:\src\SalesOrder.QueryService\ToolBelt.Tests.Extensions\out\
  ToolBelt.Mapping.Contracts -> C:\src\SalesOrder.QueryService\ToolBelt.Mapping.Contracts\out\
  SalesOrder.Cmd.Application.Model -> C:\src\SalesOrder.QueryService\SalesOrder.Cmd.Application.Model\out\
  ToolBelt.Hateoas -> C:\src\SalesOrder.QueryService\ToolBelt.Hateoas\bin\Release\netstandard2.0\ToolBelt.Hateoas.dll
  SalesOrder.Cmd.Application.Model.Events -> C:\src\SalesOrder.QueryService\SalesOrder.Cmd.Application.Model.Events\bin\Release\netstandard2.0\SalesOrder.Cmd.Application.Model.Events.dll
  SalesOrder.Cmd.Application.Model.Events -> C:\src\SalesOrder.QueryService\SalesOrder.Cmd.Application.Model.Events\out\
  ToolBelt.Hateoas -> C:\src\SalesOrder.QueryService\ToolBelt.Hateoas\out\
  SalesOrder.Qry.Application -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Application\bin\Release\netstandard2.0\SalesOrder.Qry.Application.dll
  SalesOrder.Qry.Domain.EventContracts -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Domain.EventContracts\bin\Release\netcoreapp2.0\SalesOrder.Qry.Domain.EventContracts.dll
  SalesOrder.Qry.Domain.EventContracts -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Domain.EventContracts\out\
  SalesOrder.Qry.Infra.InMemoryRepository -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Infra.InMemoryRepository\bin\Release\netcoreapp2.0\SalesOrder.Qry.Infra.InMemoryRepository.dll
  SalesOrder.Qry.WebApi -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApi\bin\Release\netstandard2.0\SalesOrder.Qry.WebApi.dll
  SalesOrder.Qry.Application -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Application\out\
  SalesOrder.Qry.Application.UnitTests -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Application.UnitTests\bin\Release\netcoreapp2.0\SalesOrder.Qry.Application.UnitTests.dll
  SalesOrder.Qry.Application.UnitTests -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Application.UnitTests\out\
  SalesOrder.Qry.Infra.InMemoryRepository -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.Infra.InMemoryRepository\out\
  SalesOrder.Qry.WebApi -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApi\out\
  SalesOrder.Qry.WebApiApp -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApiApp\bin\Release\netcoreapp2.0\SalesOrder.Qry.WebApiApp.dll
  SalesOrder.Qry.WebApiApp -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApiApp\out\
  SalesOrder.Qry.WebApi.UnitTests -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApi.UnitTests\bin\Release\netcoreapp2.0\SalesOrder.Qry.WebApi.UnitTests.dll
  SalesOrder.Qry.WebApi.UnitTests -> C:\src\SalesOrder.QueryService\SalesOrder.Qry.WebApi.UnitTests\out\

这怎么可能?

我尝试在 NuGet.Config 添加以下代理设置
C:\Users\iberodev\AppData\Roaming\NuGet\NuGet.Config
``






没有运气。结果一样。我真的坚持这一点,我在任何地方都找不到好的答案,只是更加困惑。

我看到建议运行 nuget.exe 配置,但据我所知 VS2017 甚至没有 nuGet.exe(请参阅 https://www.nuget.org/downloads 解释)

这可能是由于在代理后面,但同样,不确定在哪里配置这些东西。我的 Docker for Windows 已经手动添加了代理配置。

任何建议将不胜感激

最佳答案

Docker 在它自己的(独立的)构建环境中运行,但默认情况下它不知道您的网络代理配置。

为了解决这个问题,this answer 给了我一个提示。我最终发出:

docker build --build-arg HTTP_PROXY=<proxy URL> --build-arg HTTPS_PROXY=<proxy URL> -t <application name>

代理 URL 遵循以下格式:http://USERNAME:PASSWORD@PROXYIP:PROXYPORT

关于Docker 无法加载源 https ://api. nuget.org/v3/index.json 的服务索引,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50347517/

10-16 23:44