Docker Unable to load the service index for source https://api.nuget.org/v3/index.json

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:srcSalesOrder.QueryServiceSalesOrder.Cmd.Application.ModelSalesOrder.Cmd.Application.Model.csproj.
  Restore completed in 43,43 ms for C:srcSalesOrder.QueryServiceSalesOrder.Cmd.Application.Model.EventsSalesOrder.Cmd.Application.Model.Events.csproj.
  Restore completed in 4,67 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.Infra.InMemoryRepositorySalesOrder.Qry.Infra.InMemoryRepository.csproj.
  Restore completed in 46,18 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.Application.UnitTestsSalesOrder.Qry.Application.UnitTests.csproj.
  Restore completed in 51,08 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApi.UnitTestsSalesOrder.Qry.WebApi.UnitTests.csproj.
  Restore completed in 32,46 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApiAppSalesOrder.Qry.WebApiApp.csproj.
  Restore completed in 12,53 ms for C:srcSalesOrder.QueryServiceToolBelt.HateoasToolBelt.Hateoas.csproj.
  Restore completed in 13,54 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApiSalesOrder.Qry.WebApi.csproj.
  Restore completed in 2,16 ms for C:srcSalesOrder.QueryServiceToolBelt.Mapping.ContractsToolBelt.Mapping.Contracts.csproj.
  Restore completed in 1,97 ms for C:srcSalesOrder.QueryServiceToolBelt.Tests.ExtensionsToolBelt.Tests.Extensions.csproj.
  Restore completed in 55,52 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApiAppSalesOrder.Qry.WebApiApp.csproj.
  Restore completed in 64,69 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.Application.UnitTestsSalesOrder.Qry.Application.UnitTests.csproj.
  Restore completed in 2,36 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.Domain.EventContractsSalesOrder.Qry.Domain.EventContracts.csproj.
  Restore completed in 2,87 ms for C:srcSalesOrder.QueryServiceSalesOrder.Qry.ApplicationSalesOrder.Qry.Application.csproj.
  SalesOrder.Cmd.Application.Model -> C:srcSalesOrder.QueryServiceSalesOrder.Cmd.Application.ModelbinReleasenetstandard2.0SalesOrder.Cmd.Application.Model.dll
  ToolBelt.Tests.Extensions -> C:srcSalesOrder.QueryServiceToolBelt.Tests.ExtensionsbinReleasenetstandard2.0ToolBelt.Tests.Extensions.dll
  ToolBelt.Mapping.Contracts -> C:srcSalesOrder.QueryServiceToolBelt.Mapping.ContractsbinReleasenetstandard2.0ToolBelt.Mapping.Contracts.dll
  ToolBelt.Tests.Extensions -> C:srcSalesOrder.QueryServiceToolBelt.Tests.Extensionsout
  ToolBelt.Mapping.Contracts -> C:srcSalesOrder.QueryServiceToolBelt.Mapping.Contractsout
  SalesOrder.Cmd.Application.Model -> C:srcSalesOrder.QueryServiceSalesOrder.Cmd.Application.Modelout
  ToolBelt.Hateoas -> C:srcSalesOrder.QueryServiceToolBelt.HateoasbinReleasenetstandard2.0ToolBelt.Hateoas.dll
  SalesOrder.Cmd.Application.Model.Events -> C:srcSalesOrder.QueryServiceSalesOrder.Cmd.Application.Model.EventsbinReleasenetstandard2.0SalesOrder.Cmd.Application.Model.Events.dll
  SalesOrder.Cmd.Application.Model.Events -> C:srcSalesOrder.QueryServiceSalesOrder.Cmd.Application.Model.Eventsout
  ToolBelt.Hateoas -> C:srcSalesOrder.QueryServiceToolBelt.Hateoasout
  SalesOrder.Qry.Application -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.ApplicationbinReleasenetstandard2.0SalesOrder.Qry.Application.dll
  SalesOrder.Qry.Domain.EventContracts -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.Domain.EventContractsbinReleasenetcoreapp2.0SalesOrder.Qry.Domain.EventContracts.dll
  SalesOrder.Qry.Domain.EventContracts -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.Domain.EventContractsout
  SalesOrder.Qry.Infra.InMemoryRepository -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.Infra.InMemoryRepositorybinReleasenetcoreapp2.0SalesOrder.Qry.Infra.InMemoryRepository.dll
  SalesOrder.Qry.WebApi -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApibinReleasenetstandard2.0SalesOrder.Qry.WebApi.dll
  SalesOrder.Qry.Application -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.Applicationout
  SalesOrder.Qry.Application.UnitTests -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.Application.UnitTestsbinReleasenetcoreapp2.0SalesOrder.Qry.Application.UnitTests.dll
  SalesOrder.Qry.Application.UnitTests -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.Application.UnitTestsout
  SalesOrder.Qry.Infra.InMemoryRepository -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.Infra.InMemoryRepositoryout
  SalesOrder.Qry.WebApi -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApiout
  SalesOrder.Qry.WebApiApp -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApiAppbinReleasenetcoreapp2.0SalesOrder.Qry.WebApiApp.dll
  SalesOrder.Qry.WebApiApp -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApiAppout
  SalesOrder.Qry.WebApi.UnitTests -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApi.UnitTestsbinReleasenetcoreapp2.0SalesOrder.Qry.WebApi.UnitTests.dll
  SalesOrder.Qry.WebApi.UnitTests -> C:srcSalesOrder.QueryServiceSalesOrder.Qry.WebApi.UnitTestsout

How’s that possible?

I’ve tried to add the following proxy settings in NuGet.Config
C:UsersiberodevAppDataRoamingNuGetNuGet.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

Source: Dockerfile Questions