dotnet restore fails from Docker container dotnet restore fails from Docker container docker docker

dotnet restore fails from Docker container


The actual error seems to be:

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

Which means that nuget is failing to access the endpoint when it is trying to download the dependencies.

There are a number of solutions to this listed here

https://github.com/NuGet/Home/issues/2880

and also

Nuget connection attempt failed "Unable to load the service index for source"


Not able to reproduce it. This is my docker file.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS baseWORKDIR /appEXPOSE 80FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS buildWORKDIR /srcCOPY ["WebApplication1.csproj", ""]COPY ["../ClassLibrary1/ClassLibrary1.csproj", "../ClassLibrary1/"]RUN dotnet restore "./WebApplication1.csproj"COPY . .WORKDIR "/src/."RUN dotnet build "WebApplication1.csproj" -c Release -o /app/buildFROM build AS publishRUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publishFROM base AS finalWORKDIR /appCOPY --from=publish /app/publish .ENTRYPOINT ["dotnet", "WebApplication1.dll"]

Different line:

COPY ["../ClassLibrary1/ClassLibrary1.csproj", "../ClassLibrary1/"]RUN dotnet restore "./WebApplication1.csproj"

I think your csproj and sln file are in different folder. When using visual studio make sure you select the option: Place solution and project file in the same folder

enter image description here

2nd Update to the answer:

With every project that you add/reference. Please add support for Docker.

This'll update the docker file.

enter image description here


Are you behind a proxy of some sort? Corporate or otherwise.

I was able to get around this issue by setting the http_proxy in my Dockerfile.

ARG HTTP_PROXY="http://username:password@proxy.example.com:8080"

Full Dockerfile example below:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-envWORKDIR /app# Copy csproj and restore as distinct layersCOPY *.csproj ./ARG HTTP_PROXY="http://username:password@proxy.example.com:8080"USER administratorRUN dotnet restore# Copy everything else and buildCOPY . ./USER administratorRUN dotnet publish -c Release -o out# Build runtime imageFROM mcr.microsoft.com/dotnet/core/aspnet:3.1WORKDIR /appCOPY --from=build-env /app/out .ENTRYPOINT ["dotnet", "myapp.dll"]