dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.83k stars 4.87k forks source link

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

Open VinayPadam opened 1 year ago

VinayPadam commented 1 year ago

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

skt005 commented 1 year ago

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

skt005 commented 1 year ago

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

Step:-

image

daveblack93 commented 1 year ago

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.

mpowrie commented 1 year ago

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!!!

balajivijayakumar1994 commented 1 year ago

hi @mpowrie ,

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

Thanks

mpowrie commented 1 year ago

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

balajivijayakumar1994 commented 1 year ago

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 commented 1 year ago

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

dgarciarubio commented 1 year ago

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
balajivijayakumar1994 commented 1 year ago

Its not working out even after adding it

jamespagedev commented 1 year ago

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?

douglasg14b commented 1 year ago

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?

jamespagedev commented 1 year ago

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.

devquestioner commented 1 year ago

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?

trunov-ms commented 1 year ago

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

echo "MaxProtocol = TLSv1.2" >> /etc/ssl/openssl.cnf && dotnet restore
sairamaj commented 1 year ago

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

balajivijayakumar1994 commented 1 year ago

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

a-chumbler commented 1 year ago

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.

dev4884 commented 1 year ago

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

stmax82 commented 1 year ago

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

pawel-baran-se commented 1 year ago

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!

HoangHuuDong commented 10 months ago

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

namilkimfree commented 9 months ago

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..

jfaigan commented 9 months ago

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!

reddyrajhanu2024 commented 7 months ago

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

this DNS doesn't help me.

jfaigan commented 7 months ago

"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.

air3ijai commented 5 months ago

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 ```yaml apiVersion: v1 kind: Pod metadata: name: ubuntu namespace: default spec: containers: - name: ubuntu image: ubuntu:22.04 command: ["sleep", "infinite"] ``` 2. Install utilities ```shell apt update && apt install -y curl dnsutils iputils-ping net-tools ``` 3. Check DNS resolving ```shell # 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 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 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 ```
angonzaleztrc commented 4 months ago

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.

hknyuc commented 3 months ago

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!

chandermalik commented 3 weeks ago

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" ]