I'm trying to download NuGet packages on Docker (Linux) for a .NET 6 application behind a corporate proxy
ARG netVersion=6.0
FROM mcr.microsoft.com/dotnet/sdk:${netVersion} AS build-env
WORKDIR /app
COPY company-root-ca.crt /usr/local/share/ca-certificates/company-root-ca.crt
RUN update-ca-certificates
COPY App/*.csproj .
RUN dotnet restore --configfile nuget.config
The dotnet restore
call fails:
#17 [build-env 10/18] RUN dotnet restore --configfile nuget.config
#17 1.083 Determining projects to restore...
#17 6.883 /app/MyApp.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#17 6.900 /usr/share/dotnet/sdk/6.0.301/NuGet.targets(130,5): error : Sequence contains no elements [/app/MyApp.csproj]
#17 ERROR: executor failed running [/bin/sh -c dotnet restore --configfile nuget.config]: exit code: 1
------
> [build-env 10/18] RUN dotnet restore --configfile nuget.config:
#17 1.083 Determining projects to restore...
#17 6.883 /app/MyApp.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#17 6.900 /usr/share/dotnet/sdk/6.0.301/NuGet.targets(130,5): error : Sequence contains no elements [/app/MyApp.csproj]
RUN curl https://api.nuget.org/v3/index.json
in the container works fine, so the internet connection using our proxy is not the problem (it is set using build args). ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
doesn't seem to have any effect, like some moficiations in the nuget.config
file which were suggested in different similiar questions/tickets:
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy usesystemdefault="true" bypassonlocal="true" />
</defaultProxy>
<settings>
<ipv6 enabled="true"/>
</settings>
</system.net>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<!--
<activePackageSource>
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</activePackageSource>
-->
</configuration>
Some references: