Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet restore works locally but fails when building Docker container

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?

like image 506
Tomas Aschan Avatar asked Sep 26 '17 20:09

Tomas Aschan


1 Answers

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.

like image 139
Johan Leino Avatar answered Oct 26 '22 08:10

Johan Leino