我遇到了同样的问题。我怀疑它与代理背后有关。 我的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 \应用程序数据\漫游\的NuGet \ NuGet.Config ```
没有运气。结果相同。我真的很困惑,我无法在任何地方找到好的答案,只是更加困惑。
我看到建议运行nuget.exe配置,但据我所知VS2017甚至没有nuGet.exe(请参阅https://www.nuget.org/downloads解释)
这可能是由于落后于代理,但又不知道在哪里配置这些东西。我的Docker for Windows已经手动添加了代理配置。
非常感谢任何建议
答案 0 :(得分:0)
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
答案 1 :(得分:0)
我遇到了类似的问题-需要一个类似于ltuska提出的代理设置建议的解决方案。
运行docker build或docker-compose build时,任何需要网络访问的RUN指令都需要一个有效的“ build”网络才能拉资源(特别是与mcr.microsoft链接的“ RUN dotnet restore”)。 com / dotnet / core / sdk:3.1高山图片需要通过HTTP GET访问https://api.nuget.org/v3/index.json)
在运行于公司数据中心的linux机器上,有两件事与标准的docker安装方案有很大不同:
“ bridge”:“ none”已在/etc/docker/daemon.json中设置,这会禁用默认的桥接网络。
要完成图像构建,我需要做两件事:
明确提供可访问Internet的docker网络(在我的情况下,可访问具有Internet访问权限的代理服务器)
明确指定代理设置
from'docker network ls'-我确定了在主机上配置为允许网桥网络流量发送到外部的现有网桥网络的名称。
使用docker build,该命令看起来类似于...
docker build --network=xxxbridge --build-arg HTTP_PROXY=http://www-proxy.yyyy:80 --build-arg HTTPS_PROXY=http://www-proxy.yyyy:80
从docker撰写的角度来看,我不得不修改docker-compose.yml并为服务指定一个明确的构建网络...
docker-compose.yml代码段:
...
services:
myService:
build:
context: ./MyService
network: xxxbridge
...
docker-compose build --build-arg HTTP_PROXY=http://www-proxy.yyyy:80 --build-arg HTTPS_PROXY=http://www-proxy.yyyy:80
答案 2 :(得分:-1)
为我解决了这个问题的方法:我在IE中的受信任站点列表(设置->安全->受信任站点)中添加了https://api.nuget.org。
希望能帮助某人。