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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you elaborate the steps you followed
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.