core icon indicating copy to clipboard operation
core copied to clipboard

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

Open VinayPadam opened this issue 2 years ago • 34 comments

Problem encountered on https://dotnet.microsoft.com/en-us/learn/aspnet/microservice-tutorial/docker-image Operating System: windows I am Geeting error while

[build 4/6] RUN dotnet restore: #11 1.569 Determining projects to restore... #11 8.229 /src/MyMicroservice.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json. #11 14.33 /src/MyMicroservice.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json. #11 14.40 Failed to restore /src/MyMicroservice.csproj (in 12.44 sec).


executor failed running [/bin/sh -c dotnet restore]: exit code: 1

VinayPadam avatar Dec 19 '22 11:12 VinayPadam

I am also new to docker and facing the same issue in RUN dotnet restore as below image

skt005 avatar Jan 04 '23 09:01 skt005

update :- Adding DNS Server into Docker Engine solve this problem

Step:-

  • Open Docker Desktop
  • Go to Setting
  • Go to Docker Engine
  • Add DNS tag in setting configuration as below

image

skt005 avatar Jan 05 '23 09:01 skt005

Hi @skt005, we have maybe the same issue with a private feed hosted in onprem gitlab istance, my question is what have you inserted in the DNS array? I mean which hostname/ip?

Thanks.

daveblack93 avatar Jan 05 '23 14:01 daveblack93

update :- Adding DNS Server into Docker Engine solve this problem

Step:-

  • Open Docker Desktop
  • Go to Setting
  • Go to Docker Engine
  • Add DNS tag in setting configuration as below

image

Thanks for posting the fix! That's crazy that the workaround is adding DNS entries to Docker!!!

mpowrie avatar Mar 07 '23 00:03 mpowrie

hi @mpowrie ,

Can you please tell me Which DNS address we have to put here in order to work.

Thanks

balajivijayakumar1994 avatar Mar 07 '23 07:03 balajivijayakumar1994

Sure - "dns":["1.1.1.1","8.8.8.8"],

mpowrie avatar Mar 07 '23 07:03 mpowrie

#13 [build 5/8] RUN dotnet restore "./myFirstProject.csproj" #13 0.587 Determining projects to restore... #13 126.6 /src/myFirstProject.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.

Still Failing After Adding DNS entry please see my docker Compose file

**#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base WORKDIR /app EXPOSE 80 EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY ["myFirstProject.csproj", "."] RUN export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 #RUN curl "www.google.com" #RUN curl -k "https://api.nuget.org/v3/index.json" RUN dotnet restore "./myFirstProject.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "myFirstProject.csproj" -c Release -o /app/build

FROM build AS publish RUN dotnet publish "myFirstProject.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "myFirstProject.dll"]**

balajivijayakumar1994 avatar Mar 07 '23 09:03 balajivijayakumar1994

in the above I am able to do both

RUN curl "www.google.com" RUN curl -k "https://api.nuget.org/v3/index.json"

when I did without -k i am getting certificate exception

balajivijayakumar1994 avatar Mar 07 '23 09:03 balajivijayakumar1994

update :- Adding DNS Server into Docker Engine solve this problem

Step:-

  • Open Docker Desktop
  • Go to Setting
  • Go to Docker Engine
  • Add DNS tag in setting configuration as below

For anyone not using docker desktop, this also works in the free alternative Container Desktop

image

dgarciarubio avatar Mar 09 '23 15:03 dgarciarubio

Its not working out even after adding it

balajivijayakumar1994 avatar Mar 15 '23 07:03 balajivijayakumar1994

I'm seeing the same issue...

I've updated my config file in desktop docker -> docker engine settings... image

However the issue still persists... image

The strange thing is, it works fine in another project... image

Anyone have any ideas?

jamespagedev avatar Apr 18 '23 00:04 jamespagedev

This just started happening to me as well, worked yesterday, hosed today. Running the docker build on WSL.

I can restore fine outside of docker.

Updating DNS did not work, anyone have ideas?

douglasg14b avatar Apr 18 '23 01:04 douglasg14b

I'm seeing the same issue...

I've updated my config file in desktop docker -> docker engine settings... image

However the issue still persists... image

The strange thing is, it works fine in another project... image

Anyone have any ideas?

So I got it to work. I'm not sure which of these steps made it work, but here they are...

I updated version 4.17 to 4.18. The update hung during the install and I had to kill all docker running processes and services. While killing the docker processes, I noticed there were .net tasks running (usually happens after running dotnet commands and they hang), so I also killed those processes to ensure nothing would be stuck in the handlers.

After starting docker back up, and clicking yes to start everything, it immediately closed docker desktop and began installing the updates. After it finished, I started docker desktop again, and waited a while for it to start up, and it did.

I executed the command again and success! image

Hope this helps anyone else here. Thanks and take care.

jamespagedev avatar Apr 18 '23 01:04 jamespagedev

Facing the below error when dotnet restore is being executed from within docker error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json

Tried setting up dns property in Docker engine as suggested above. But no luck. Packages are getting restored from Visual studio as well dotnet restore command also is working fine when executed outside docker. Issue seen only when ran with docker.

Any solutions?

devquestioner avatar May 30 '23 10:05 devquestioner

Setting up "MaxProtocol" to TLS 1.2. For example on ubuntu image

echo "MaxProtocol = TLSv1.2" >> /etc/ssl/openssl.cnf && dotnet restore

trunov-ms avatar May 30 '23 13:05 trunov-ms

For me the below steps before dotnet restore worked as ZScaler is installed on my machine. Exported ZScaler from Certificate store.

COPY zscalar.cer . ADD zscalar.cer /usr/local/share/ca-certificates/zscalar.cer ADD zscalar.cer /etc/ssl/certs/zscalar.cer RUN chmod 644 /usr/local/share/ca-certificates/zscalar.cer && update-ca-certificates

sairamaj avatar May 31 '23 21:05 sairamaj

I think it could be firewall issue with laptop on accessing the URls from docker image

balajivijayakumar1994 avatar Jun 22 '23 07:06 balajivijayakumar1994

Hey, I had the same issue, and I figured out that this problem disappears when I install curl or wget. So I added the following line to my Dockerfile before running dotnet publish:

RUN apt-get install -y wget

It seems like the distribution is missing some packages required for performing HTTPS calls.

a-chumbler avatar Jul 12 '23 13:07 a-chumbler

Hi All, I was also facing same issue and spend many days to resolve it but no luck, thanks to this article which helped me a lot. Article URL:- http://blogswithdev.com/docker-issue

dev4884 avatar Aug 06 '23 19:08 dev4884

apt install curl fixed it for me. Got this error in ubuntu:latest. It's gone after adding curl... try it, maybe it helps.

stmax82 avatar Aug 07 '23 14:08 stmax82

apt install curl fixed it for me. Got this error in ubuntu:latest. It's gone after adding curl... try it, maybe it helps.

This worked for me too. Thank you!

pawel-baran-se avatar Aug 08 '23 05:08 pawel-baran-se

I have this problem when build docker image

I have setting docker desktop like this : image

But still Error. Please help me !!

My project and csproj: image image

HoangHuuDong avatar Oct 30 '23 05:10 HoangHuuDong

i have same issue

docker file build of vs2022

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

docker setting add dns section

"dns":["1.1.1.1","8.8.8.8"]

help me..

namilkimfree avatar Nov 04 '23 14:11 namilkimfree

For me the below steps before dotnet restore worked as ZScaler is installed on my machine. Exported ZScaler from Certificate store.

COPY zscalar.cer . ADD zscalar.cer /usr/local/share/ca-certificates/zscalar.cer ADD zscalar.cer /etc/ssl/certs/zscalar.cer RUN chmod 644 /usr/local/share/ca-certificates/zscalar.cer && update-ca-certificates

YES!!! This works for me! I am so glad I found this. I have been banging my head against this wall for way too long!

jfaigan avatar Nov 04 '23 17:11 jfaigan

"dns":["1.1.1.1","8.8.8.8"],

this DNS doesn't help me.

reddyrajhanu2024 avatar Jan 23 '24 06:01 reddyrajhanu2024

"dns":["1.1.1.1","8.8.8.8"],

this DNS doesn't help me.

FYI, it did not help me either. My problem was that I was being blocked from accessing the Internet from inside the container. I needed to provide the root certificate in order to succeed. You can see my previous post for details.

Hope this helps.

jfaigan avatar Jan 23 '24 15:01 jfaigan

In our case we run Kubernetes using Docker Desktop and deployed dotnet application, which stuck with a similar error

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

DNS name api.nuget.org can't be resolved inside the Pod and probably because of the networking related issue. However, most of the other names resolved successfully.

Did a try to set different MTU, but still see same 1500 inside the Pod

vi "$HOME/Library/Group Containers/group.com.docker/settings.json"

  "vpnKitMTU": 1472,
checks
  1. Deploy a simple Pod with Ubuntu

    apiVersion: v1
    kind: Pod
    metadata:
      name: ubuntu
      namespace: default
    spec:
      containers:
        - name: ubuntu
          image: ubuntu:22.04
          command: ["sleep", "infinite"]
    
  2. Install utilities

    apt update && apt install -y curl dnsutils iputils-ping net-tools
    
  3. Check DNS resolving

    # curl - fail
    curl -m 5 https://api.nuget.org/v3/index.json
    
    curl: (28) Resolving timed out after 5000 milliseconds
    
    
    # ping - fail
    ping api.nuget.org
    
    ping: api.nuget.org: Temporary failure in name resolution
    
    
    # nslookup - fail
    nslookup api.nuget.org
    
    nslookup api.nuget.org
    Server:         10.96.0.10
    Address:        10.96.0.10#53
    
    ** server can't find api.nuget.org: SERVFAIL
    
    # nslookup over TCP - success
    nslookup -vc api.nuget.org
    
    Server:         10.96.0.10
    Address:        10.96.0.10#53
    
    Non-authoritative answer:
    api.nuget.org   canonical name = nugetapiprod.trafficmanager.net.
    nugetapiprod.trafficmanager.net canonical name = apiprod-mscdn.azureedge.net.
    apiprod-mscdn.azureedge.net     canonical name = apiprod-mscdn.afd.azureedge.net.
    apiprod-mscdn.afd.azureedge.net canonical name = azureedge-t-prod.trafficmanager.net.
    azureedge-t-prod.trafficmanager.net     canonical name = shed.dual-low.part-0016.t-0009.t-msedge.net.
    shed.dual-low.part-0016.t-0009.t-msedge.net     canonical name = part-0016.t-0009.t-msedge.net.
    Name:   part-0016.t-0009.t-msedge.net
    Address: 13.107.246.44
    Name:   part-0016.t-0009.t-msedge.net
    Address: 13.107.213.44
    Name:   part-0016.t-0009.t-msedge.net
    Address: 2620:1ec:46::44
    Name:   part-0016.t-0009.t-msedge.net
    Address: 2620:1ec:bdf::44
    
    
    # dig - success
    dig api.nuget.org
    
    ; <<>> DiG 9.16.48-Debian <<>> api.nuget.org
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39150
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4096
    ; COOKIE: 5265cadb46e3622a (echoed)
    ;; QUESTION SECTION:
    ;api.nuget.org.                 IN      A
    
    ;; ANSWER SECTION:
    api.nuget.org.          30      IN      CNAME   nugetapiprod.trafficmanager.net.
    nugetapiprod.trafficmanager.net. 30 IN  CNAME   apiprod-mscdn.azureedge.net.
    apiprod-mscdn.azureedge.net. 30 IN      CNAME   apiprod-mscdn.afd.azureedge.net.
    apiprod-mscdn.afd.azureedge.net. 30 IN  CNAME   azureedge-t-prod.trafficmanager.net.
    azureedge-t-prod.trafficmanager.net. 30 IN CNAME shed.dual-low.part-0016.t-0009.t-msedge.net.
    shed.dual-low.part-0016.t-0009.t-msedge.net. 30 IN CNAME part-0016.t-0009.t-msedge.net.
    part-0016.t-0009.t-msedge.net. 30 IN    A       13.107.213.44
    part-0016.t-0009.t-msedge.net. 30 IN    A       13.107.246.44
    
    ;; Query time: 16 msec
    ;; SERVER: 10.96.0.10#53(10.96.0.10)
    ;; WHEN: Fri Mar 29 13:25:16 UTC 2024
    ;; MSG SIZE  rcvd: 604
    
  4. Check MTU

    # 1472 - success
    ping -c 3 -M do -s 1472 bing.com
    PING bing.com (204.79.197.200) 1472(1500) bytes of data.
    1480 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=1 ttl=63 time=16.9 ms
    1480 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=2 ttl=63 time=19.6 ms
    1480 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=3 ttl=63 time=24.8 ms
    
    --- bing.com ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2005ms
    rtt min/avg/max/mdev = 16.916/20.423/24.771/3.261 ms
    
    
    # 1474 - fail
    ping -c 3 -M do -s 1474 bing.com
    PING bing.com (13.107.21.200) 1474(1502) bytes of data.
    ping: local error: message too long, mtu=1500
    ping: local error: message too long, mtu=1500
    ping: local error: message too long, mtu=1500
    
    --- bing.com ping statistics ---
    3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2061ms
    
    # Container MTU
    ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 10.1.0.130  netmask 255.255.0.0  broadcast 10.1.255.255
            ether be:ed:71:06:43:22  txqueuelen 0  (Ethernet)
            RX packets 5366  bytes 44885370 (44.8 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 3962  bytes 277004 (277.0 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

air3ijai avatar Mar 29 '24 18:03 air3ijai

update :- Adding DNS Server into Docker Engine solve this problem

Step:-

  • Open Docker Desktop
  • Go to Setting
  • Go to Docker Engine
  • Add DNS tag in setting configuration as below

image

this fixed the issue for me.

angonzaleztrc avatar Apr 05 '24 20:04 angonzaleztrc

apt install curl worked for me.

apt install curl fixed it for me. Got this error in ubuntu:latest. It's gone after adding curl... try it, maybe it helps.

Thank you so much!

hknyuc avatar May 24 '24 13:05 hknyuc

Adding DNS entry worked for me. It is an issue docker intermediate container is not able to reach api.nuget.org. It could be due to firewall , vpn or any other issue specific to respective machine.

"dns": [ "1.1.1.1", "8.8.8.8" ]

chandermalik avatar Aug 03 '24 03:08 chandermalik