7

If I create a new console application using dotnet classlib -lang f# -o hello-docker, cd into the directory and then run dotnet restore, everything works as expected.

However, if I add a Dockerfile with the following content

FROM microsoft/dotnet:2-sdk

WORKDIR /hello

COPY hello-docker.fsproj .
COPY *.fs ./

RUN dotnet restore

RUN dotnet build

ENTRYPOINT [ "dotnet", "run" ]

and run docker build ., it fails to reach nuget.org with the following message:

/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/hello/hello-docker.fsproj]
/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5): error : An error occurred while sending the request. [/hello/hello-docker.fsproj]
/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5): error : Couldn't resolve host name [/hello/hello-docker.fsproj]
The command '/bin/sh -c dotnet restore' returned a non-zero code: 1

Why can I restore locally, but not inside the Docker container?

10
  • You are using which OS? Commented Sep 27, 2017 at 6:17
  • @tarunlalwani Windows 10. Commented Sep 27, 2017 at 6:38
  • 3
    I think for some reason internet is not working in your Docker containers. Try restarting the docker VM from settings Commented Sep 27, 2017 at 6:50
  • 1
    Honestly not sure, try getting rid of docker and reinstalling it and see if it is of any help Commented Sep 27, 2017 at 8:34
  • 1
    Yeah, reinstalling docker did the trick. Weird, but I guess there was some firewall rule somewhere that borked it. Thanks! Commented Sep 28, 2017 at 6:27

1 Answer 1

5

I fixed it by going into properties/sharing on my network adapter and shared it with the hyper-v/docker switch...think it was called nat or something.

2
  • 2
    Can you elaborate the steps you followed
    – Shankar S
    Commented Jan 18, 2019 at 9:57
  • 2
    for me (on windows 10), i right clicked the wifi icon at the bottom right, click "Open network & Internet Settings" then click "Change adapter options", then right click the current adapter I was using for internet (wifi in my case), click properties, go to sharing tab, click "allow other network users to connect through this computer's internet connection" then from the dropdown i picked vEthernet (DockerNAT) or whatever is equivalent for your machine
    – ctoph
    Commented Oct 31, 2019 at 1:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.