7
votes

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?

1
You are using which OS?Tarun Lalwani
@tarunlalwani Windows 10.Tomas Aschan
I think for some reason internet is not working in your Docker containers. Try restarting the docker VM from settingsTarun Lalwani
Honestly not sure, try getting rid of docker and reinstalling it and see if it is of any helpTarun Lalwani
Yeah, reinstalling docker did the trick. Weird, but I guess there was some firewall rule somewhere that borked it. Thanks!Tomas Aschan

1 Answers

5
votes

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.