45

https://github.com/dotnet/dotnet-docker-samples/tree/master/aspnetapp

Docker command docker build -t aspnetapp.

I am getting an error for docker build command as

C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\aspnetapp.csproj]

error message screenshot

[1]PS C:\Users\pssharma\dotnet-docker-samples\aspnetapp> docker build -t aspnetapp .
Sending build context to Docker daemon  2.444MB
Step 1/10 : FROM microsoft/aspnetcore-build:2.0 AS build-env
 ---> eb21d939e0d8
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> d4ec30216ed7
Step 3/10 : COPY *.csproj ./
 ---> Using cache
 ---> 2ff39b5e6cb4
Step 4/10 : RUN dotnet restore
 ---> Running in 776764a35311
  Restoring packages for C:\app\aspnetapp.csproj...
  Restoring packages for C:\app\aspnetapp.csproj...
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\asp
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error :   An error occurred while sending the request. [C:\app\aspnetapp.csproj]
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error :   The operation timed out [C:\app\aspnetapp.csproj]

The following command returned a non-zero code: 1

powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; dotnet restore

error message screenshot

Frodon
  • 3,684
  • 1
  • 16
  • 33
Pavan sharma
  • 451
  • 1
  • 4
  • 4
  • 1
    On few earlier versions I had to restart docker service to resolve issues like this. Could you try to restart it and retry the build from an administrator powershel consolel: `Restart-Service com.docker.service -Force` – muratiakos Apr 26 '18 at 10:14
  • 1
    Hi,I tried with Administrator PowerShell but getting same error. – Pavan sharma Apr 26 '18 at 11:58
  • Is there any way to check the logs for this. – Pavan sharma Apr 26 '18 at 12:59
  • 8
    You can try to add `RUN curl https://api.nuget.org/v3/index.json -v` and `RUN dotnet restore --verbosity diag` in your DockerFile to see what it is doing - if only restore fails or both with curl too. – muratiakos Apr 26 '18 at 13:55
  • 1
    I getting same error this is Dockerfile FROM microsoft/aspnetcore-build:2.0 AS build-env WORKDIR /app # copy csproj and restore as distinct layers COPY *.csproj ./ 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", "aspnetapp.dll"] – Pavan sharma Apr 26 '18 at 14:32
  • 1
    I am having the same issue. Have you resolved? – diegosasw May 15 '18 at 08:31
  • @iberodev did you get it resolved? – Parth Trivedi Feb 11 '19 at 14:37
  • no @ParthTrivedi – diegosasw Feb 11 '19 at 16:18
  • @iberodev i get it fixes. My issue is with corporate firewall. – Parth Trivedi Feb 12 '19 at 08:11
  • Which container are you using? Linux or Windows? I had same issue with windows container because I was using linux image – Chander .k Aug 24 '20 at 09:31
  • 1
    Do you have a corporate VPN running on your machine? – Jelle Schräder Feb 19 '21 at 08:21
  • I had the same issue when i did `docker-compose build`. docker build could not connect to the public or private nuget feed. I had corp VPN enabled as well. then I did a `RUN curl https://api.nuget.org/v3/index.json -v` step in the docker image and turned out corp firewall was breaking SSL apart. whitelisting the feed domains fixed it – Romesh D. Niriella Sep 14 '22 at 01:54

15 Answers15

37

This appears to happen when there are multiple network adaptors present for the host and the priority of said adaptor is misconfigured. Run the following to display a table of your network adaptors:

Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending

You want your primary adaptor (in my case wifi) to have the lowest InterfaceMetric.

Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 1

My network adaptor table for reference: enter image description here

See this github thread for more information: https://github.com/docker/for-win/issues/2760#issuecomment-430889666

PontiusTheBarbarian
  • 1,004
  • 9
  • 17
  • 1
    This works for me ! .NetCore sdk 3.1.300 web app, windows container. Try run powershell as Administrator. Check this out also : https://improveandrepeat.com/2019/09/how-to-fix-network-errors-with-docker-and-windows-containers/ – Sorin B. Jun 09 '20 at 09:19
  • I'm new to this docker business, and I'm stunned that this answer worked! And yes - RUN POWERSHELL AS ADMIN. Also: "WiFi" wasn't hyphenated in my list - watch out folks @_@ – Dave Jun 15 '22 at 15:22
  • This worked as a charm. I had two network adapters in my computer and they had wrong priorities. I had to "run it as administrator". This works! – Carlos R Balebona Jan 22 '23 at 02:48
18

For me, this issue appeared randomly (along with multiple similar issues, such as "permission denied for nuget" etc. To fix that, restart Visual Studio) For windows, it was fixed by restarting docker service and restarting Visual Studio (2017).

  1. Shut down Docker and Visual Studio
  2. Winkey + R, type in services.msc
  3. Find Docker for Windows Service and restart it (restarting Docker normally is not enough)
  4. Start Docker and Visual Studio
  • it worked even in MacOS. I stopped Docker and boom! Thanks – Tomamais Sep 05 '18 at 16:52
  • running eShopOnContainer app on Linux container,when i run docker-compose build throws error:Unable to load the service index for source https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json. [/src/eShopOnContainers-ServicesAndWebApps.sln] /usr/share/dotnet/sdk/3.1.201/NuGet.targets(124,5): error : Connection refused [/src/eShopOnContainers-ServicesAndWebApps.sln] ERROR: Service 'webstatus' failed to build: The command '/bin/sh -c dotnet restore "eShopOnContainers-ServicesAndWebApps.sln"' returned a non-zero code: 1 PS C:\Projects\eShopOnContainers-dev\eShopOnContainers-dev\src> – Saad Awan Apr 08 '20 at 11:20
16

Just add --network=host option to docker build

docker build -t aspnetapp . --network=host

Ilko
  • 1,288
  • 1
  • 14
  • 19
  • If you are running the `docker build` command in a container itself (#containerception), then this will resolve external dependencies as the network is otherwise limited to the container host. It worked for me when I was running a local task runner using GitHub Actions. I am not sure if this would solve the problem if you are running the `docker build` on bare metal (or a VM). Hopefully this helps clarify why this might or might not work. – Mike S. Mar 29 '20 at 23:08
5

I got this working by passing in docker build environment variables from the command line like so:

docker build --build-arg HTTP_PROXY=http://{un}:{pw}@{proxyhost}:{port} --build-arg HTTPS_PROXY=http://{un}:{pw}@{proxyhost}:{port} -t aspnetapp .

*note that your username must be url encoded (ei. DOMAIN\name => DOMAIN%5Cname)

patrickbadley
  • 2,510
  • 2
  • 29
  • 30
  • This did not work for me. How did you determine the proxy address and port? – Robotronx Oct 19 '20 at 22:38
  • 1
    @Robotron I think you'll need to get that info from your network admin. I posted this some time ago and am no longer at the client where I had to find a solution for this. Sorry I can't provide more help now, but good luck! – patrickbadley Oct 21 '20 at 00:47
3

Had the same issue, the problem was a missing dependency used by NuGet.

I am using the microsoft/dotnet:sdk image, and it works after installing libcurl3 to my image.

Try adding RUN apt-get update && apt-get install -y libcurl3 to your Dockerfile before restoring.

if it doesn't work, try restarting your Docker instance.

edit: if that doesn't help you, there is this open issue on the NuGet github where some people are trying to solve the same problem.

edit2:added Ignas solution: restarting docker instance.

  • 2
    Found in the GitHub issue referenced in the answer -- needed to restart my Docker instance. – Ignas Jan 15 '19 at 11:40
  • 'http://security.debian.org/debian-security buster/updates InRelease' is not signed. Failed to fetch http://security.debian.org/debian-ecurity/dists/buster/updates/InRelease 403 Forbidden by security policy [IP: 'http://deb.debian.org/debian buster InRelease' is not signed. Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease 403 Forbidden by security policy The repository 'http://deb.debian.org/debian buster-updates InRelease' is not signed. The command '/bin/sh -c apt-get update && apt-get install -y libcurl3' returned a non-zero code: 100 – Satendra Jindal Apr 18 '20 at 17:50
  • This didn't solve it for me, but I wanted to say that I needed to use libcurl4 since libcurl3 is old now. – Don Rolling Sep 29 '22 at 18:07
3

I'm suprised no one said this already. This was caused by not having the latest sdk installed. In my case docker was looking for the file

C:\Program Files\dotnet\sdk\3.1.302\NuGet.targets

However this file did not exist on my machine instead I had a different minor version.

C:\Program Files\dotnet\sdk\3.1.301\NuGet.targets

I'm sure they're away to get it working using an older version, but in my case I just updated the downloaded the latest sdk

johnny 5
  • 19,893
  • 50
  • 121
  • 195
1

If the issue is caused by your organisation's self-signed certificates, you can fix it by:

  1. Get the certificate file (*.cer) provided by your IT department.
  2. Copy it into the SSL certificate location: COPY ["./combined.cer", "/etc/ssl/certs/"]
  3. Update SSL cert list: RUN update-ca-certificates

These steps work for Debian, need to be adapted for other distros.

Mansoor
  • 2,357
  • 1
  • 17
  • 27
1

configuring the dns in the docker engine helped me you go to docker setting then to docker engine you can see a json formatted doc you add this :

"dns": ["10.0.0.2","8.8.8.8"]

then restart docker i wish that helps you

Dark Storm
  • 187
  • 4
  • 10
0

Open CMD or Powershell and run: dotnet nuget locals http-cache --clear

https://status.nuget.org/

Le Tin
  • 9
  • 1
  • Welcome to StackOverflow! Adding an explanation to your answer will help others understand how does it help with the problem. – Acapulco Oct 16 '18 at 16:41
  • Also, I don't think this answer applies because the OP is looking for a proxy solution for a Docker environment. – joshmcode Dec 21 '18 at 00:26
0

In my case, in Dockerfile, I have

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build

and

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2

But I only have .net 2.1 installed (view by dotnet --list-sdks). So I have to change 2.2 to 2.1 to make it work.

Quan VO
  • 1,258
  • 11
  • 19
  • I know this is an old one, and I have NO idea why docker would be affected by this when building on OSX, but this did it for me. I was building with `sdk:3.1` but have `3.0` locally. Download and install `3.1` for osx and *boom* it works. WTF, why is docker affected by whats installed on my host! Maybe dotnet restore is somehow searching localhost first, but by what mechanism I don't know. – Andrew Dec 09 '19 at 04:18
  • Yes, no way to check is on purpose. It is best not to assume. – Andrew Mar 29 '23 at 02:21
0

After one hour fighting with proxy, finally following solution worked just fine for me:

docker build --build-arg HTTP_PROXY=http://xxxx.com:8080 --build-arg HTTPS_PROXY=http://yyyy:8080 -t kdekarin/aspnet .

See @patrickbadley's comment for more info!

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

One more reason why this happens. If your docker file targeting windows container and your docker is running linux mode or vice versa.

Alpesh
  • 606
  • 6
  • 15
0

It helps me: Docker Desktop -> Troubleshoot -> Reset to factory defaults

-1

I had the same issue on Debian 9. I fudge the error with disconnecting from local network. It works for me because I did not change anything on codebase and I do not need to get packages from nuget.

mcemilg
  • 976
  • 1
  • 11
  • 18
-1

I got this resolved on my Windows 10 Machine by Disabling Avast Antivirus and unInstalling McAffee Antivirus.

  • Right click the Avast Icon in the Notification Tab
  • Select Avast Shields Control
  • Click on "Disable Until Computer is Restarted".

And you can now run the Docker Build Successfully. I can give Further Assistance if needed.

Ebube
  • 475
  • 4
  • 5