4

I am having the same issue. I suspect it's something to do with being behind a proxy. My Dockerfile is:

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"]

and I am getting an error on the step that publishes with 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

However if I run the very same instruction directly I don't get that error:

$ 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\

How's that possible?

I've tried to add the following proxy settings in NuGet.Config C:\Users\iberodev\AppData\Roaming\NuGet\NuGet.Config ```

No luck. Same result. I'm really stuck with this and I cannot find good answers anywhere, just more confusion.

I see advises to run nuget.exe config but as far as I understand VS2017 does not even have a nuGet.exe (see https://www.nuget.org/downloads explaining it)

It could be due to being behind a proxy, but again, not sure where to configure these things. My Docker for Windows has already the proxy configuration added manually.

Any advice would be much appreciated

diegosasw
  • 13,734
  • 16
  • 95
  • 159
  • I have the same problem did you find a solution ? /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. – yaniv Jun 03 '18 at 18:50
  • No. I haven't found a solution – diegosasw Jun 09 '18 at 09:03
  • 1
    i did , the company firewall did "SSL inspection" on out requests and change the SSL certificate of NuGet site. we add an firewall exception to the IP of the build server not to do it. – yaniv Jun 09 '18 at 17:13
  • @yaniv will this solve your issue? – Parth Trivedi Feb 11 '19 at 14:32

4 Answers4

5

Docker is running in it's own (separated) build environment, but per default it is not aware of your network proxy configuration.

To solve the problem, this answer gave me a hint. I ended up issuing:

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

The proxy URL follows this format: http://USERNAME:PASSWORD@PROXYIP:PROXYPORT

ltuska
  • 661
  • 7
  • 12
  • It works. I have to put --build-arg option the end of command or it doesn't work, I don't know why. – Simon Jan 18 '22 at 01:01
0

I hit a similar issue - and required a solution similar to what ltuska proposed with proxy settings.

When running a docker build or docker-compose build, any RUN instructions which require network access will need a valid "build" network in order to pull resources (in particular the "RUN dotnet restore" linked with the mcr.microsoft.com/dotnet/core/sdk:3.1-alpine image requires HTTP GET access to https://api.nuget.org/v3/index.json)

On my linux machine running in a corporate data centre, two things were quite different to a stock standard docker installation scenario:

  1. The default docker bridge network had been disabled
  2. Outbound access to public internet resources required a connection through a proxy server

"bridge":"none" had been set in /etc/docker/daemon.json which disables the default bridge network.

To allow the image build to complete I needed to do two things:

  1. explicitly supply a docker network that has access to internet (or in my case access to a proxy server with internet access)

  2. explicitly specify proxy settings

from 'docker network ls' - I identified the name of existing bridge network that is configured on the host to allow bridge network traffic to be sent to outside world.

Using docker build, the command looked similar to ...

docker build --network=xxxbridge --build-arg HTTP_PROXY=http://www-proxy.yyyy:80 --build-arg HTTPS_PROXY=http://www-proxy.yyyy:80

From a docker compose perspective, I had to modify the docker-compose.yml and specify an explicit build network for the service ...

docker-compose.yml snippet:

...
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

  • Not sure if there's been a version change, but I just get `MSBUILD : error MSB1001:Unknown switch. Switch: --build-arg` – Sean Aug 13 '21 at 10:44
0

In addition to what has been said:

Docker Desktop proxy settings - used when downloading the base images during the build phase. Without it you will get an error and you cannot download the base image if that image comes from an external resource / outside corporate VPN (current scenario with microsoft/aspnetcore-build).

Docker build command line proxy args --build-arg - used by NuGet and other commands as part of the build itself when they need to access a public feed (outside corporate VPN). It may still work without proxy for private NuGet repositories.

Setting ENVs HTTP_PROXY and HTTPS_PROXY inside the dockerfile - used at runtime if the container needs to access external resources. Note that you may need to set NO_PROXY for localhost and/or other internal resources (inside corporate network)

Cristian Rusanu
  • 452
  • 5
  • 15
-2

What solved the issue for me: I added https://api.nuget.org to the list of trusted sites in IE (settings -> security -> trusted sites).

Hope that helps someone.