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?

anatol
  • 1,680
  • 2
  • 24
  • 47
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • You are using which OS? – Tarun Lalwani Sep 27 '17 at 06:17
  • @tarunlalwani Windows 10. – Tomas Aschan Sep 27 '17 at 06:38
  • 3
    I think for some reason internet is not working in your Docker containers. Try restarting the docker VM from settings – Tarun Lalwani Sep 27 '17 at 06:50
  • @tarunlalwani Yes, I tried that but without success. I've also rebooted the entire machine without the problem going away. – Tomas Aschan Sep 27 '17 at 06:52
  • I don't see anything specific on the MobyVM which does that kind of connection sharing. Open HyperV manager and in the mobyvm try adding a additional NAT network manually and see if it helps – Tarun Lalwani Sep 27 '17 at 07:03
  • @TarunLalwani I managed to test this on a different computer now, and here it works, which I guess means that there's something fishy with the config on the laptop where it fails. I'll try again tonight and see if I can dig deeper into the config of that machine, but what am I looking for? – Tomas Aschan Sep 27 '17 at 08:28
  • 1
    Honestly not sure, try getting rid of docker and reinstalling it and see if it is of any help – Tarun Lalwani Sep 27 '17 at 08:34
  • 1
    Yeah, reinstalling docker did the trick. Weird, but I guess there was some firewall rule somewhere that borked it. Thanks! – Tomas Aschan Sep 28 '17 at 06:27
  • Glad, its solved for you :-). Sometimes first time installation are not perfect. I have seen it in few other places also. – Tarun Lalwani Sep 28 '17 at 06:30
  • Did you try to use the `--network host` flag, e.g. `docker build --network host`? – njappboy Feb 10 '20 at 06:10

1 Answers1

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.

Johan Leino
  • 3,473
  • 1
  • 26
  • 27
  • 2
    Can you elaborate the steps you followed – Shankar S Jan 18 '19 at 09: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 Oct 31 '19 at 01:17