1

I have a problem with dotnet restore command used in docker container behind corporate proxy.

#10 [build 6/6] RUN dotnet restore "BFG.TestApi.csproj" --verbosity n
#10 sha256:bd31c78e09fe330c27e994c0d9b5b055df2d905c280a061a634ae34765217a9a
#10 0.598 Build started 08/04/2022 06:00:42.
#10 1.000      1>Project "/src/BFG.TestApi/BFG.TestApi.csproj" on node 1 (Restore target(s)).
#10 1.000      1>_GetAllRestoreProjectPathItems:
#10 1.000          Determining projects to restore...
#10 1.252        Restore:
#10 1.252          Restoring packages for /src/BFG.TestApi/BFG.TestApi.csproj...
#10 7.564      1>/src/BFG.TestApi/BFG.TestApi.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#10 13.55      1>/src/BFG.TestApi/BFG.TestApi.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#10 13.57          Generating MSBuild file /src/BFG.TestApi/obj/BFG.TestApi.csproj.nuget.g.props.
#10 13.57          Generating MSBuild file /src/BFG.TestApi/obj/BFG.TestApi.csproj.nuget.g.targets.
#10 13.57          Writing assets file to disk. Path: /src/BFG.TestApi/obj/project.assets.json
#10 13.58          Failed to restore /src/BFG.TestApi/BFG.TestApi.csproj (in 12.35 sec).
#10 13.59          
#10 13.59          NuGet Config files used:
#10 13.59              /src/BFG.TestApi/NuGet.Config
#10 13.59              /root/.nuget/NuGet/NuGet.Config
#10 13.59          
#10 13.59          Feeds used:
#10 13.59              https://api.nuget.org/v3/index.json
#10 13.59      1>Done Building Project "/src/BFG.TestApi/BFG.TestApi.csproj" (Restore target(s)) -- FAILED.
#10 13.59 
#10 13.59 Build FAILED.
#10 13.59 
#10 13.59        "/src/BFG.TestApi/BFG.TestApi.csproj" (Restore target) (1) ->
#10 13.59        (Restore target) -> 
#10 13.59          /src/BFG.TestApi/BFG.TestApi.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#10 13.59          /src/BFG.TestApi/BFG.TestApi.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#10 13.59 
#10 13.59     0 Warning(s)
#10 13.59     2 Error(s)
#10 13.59 
#10 13.59 Time Elapsed 00:00:12.99
#10 ERROR: executor failed running [/bin/sh -c dotnet restore "BFG.TestApi.csproj" --verbosity n]: exit code: 1

What I have tried already:

  • Setting http_proxy,https_proxy in container environment variables like http://user:password@someproxyhost.com:port
  • Passing NuGet.Config file with proxy settings into project folder and also into user config path /root/.nuget/NuGet/NuGet.Config
  • I have confirmend that the proxy I am setting in container is correct because curl https://api.nuget.org/v3/index.json from inside container is working.
  • I have tried different docker images (mcr.microsoft.com/dotnet/sdk:6.0, mcr.microsoft.com/dotnet/sdk:7.0, etc)

Everything without luck.. I am struggling with this blocking issue for days now. Is there any chance that I still have some configuration issues or there is a problem with dotnet restore?

Update 1: I am using standard Dockerfile generated by VS2022 for simple WebApi project in .net 6.

artyr
  • 11
  • 3
  • How does your `docker build` command look like? It has to look like this: `docker build --build-arg http_proxy=http://my.proxy.com:3128/ --build-arg https_proxy=http://my.proxy.com:3128/ .` - at least this works for me – mu88 Aug 04 '22 at 11:02
  • I have set `ENV http_proxy=http://user:password@proxy.com:port` in Dockerfile, and that environment variable is set correctly, because for eg. `apt-get` or `curl` use it properly. – artyr Aug 04 '22 at 12:52
  • Okay, the web is full of this error and there are various cases in which it is *not* a network error here some links: https://stackoverflow.com/questions/60960955/dotnet-restore-fails-from-docker-container https://stackoverflow.com/questions/41185443/nuget-connection-attempt-failed-unable-to-load-the-service-index-for-source – mu88 Aug 04 '22 at 13:16
  • I just received confirmation from network admin that these calls to `https://api.nuget.org` does not hit proxy at all and are blocked on FW. – artyr Aug 04 '22 at 13:18
  • I've found out that we have NTLM proxy and Debian from inside contaier just can't use this type of proxy. I've set up an `cntlm` proxy service inside container, then set http_proxy to 127.0.0.1:3128, and `dotnet restore` executed without errors! Is there any better option to configure NTLM proxy for `dotnet restore`? – artyr Aug 08 '22 at 05:24

0 Answers0