dotnet恢复在本地工作,但在构建Docker容器时失败

Tom*_*han 6 docker windows-10 .net-core

如果我使用创建一个新的控制台应用程序dotnet classlib -lang f# -o hello-dockercd进入目录,然后运行dotnet restore,如预期一切正常。

但是,如果我添加Dockerfile以下内容

FROM microsoft/dotnet:2-sdk

WORKDIR /hello

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

RUN dotnet restore

RUN dotnet build

ENTRYPOINT [ "dotnet", "run" ]
Run Code Online (Sandbox Code Playgroud)

并运行docker build .,它无法达到nuget.org以下消息:

/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5):错误:无法加载源https://api.nuget.org/v3/index.json的服务索引。[/hello/hello-docker.fsproj]
/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5):错误:发送请求时发生错误。[/hello/hello-docker.fsproj]
/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5):错误:无法解析主机名[/hello/hello-docker.fsproj]
命令“ / bin / sh -c dotnet restore”返回非零代码:1

为什么我可以在本地还原,但不能在Docker容器内部还原?

Joh*_*ino 5

我通过进入我的网络适配器上的属性/共享来修复它并与 hyper-v/docker 开关共享它......认为它被称为 nat 或其他东西。

  • 你能详细说明你遵循的步骤吗 (2认同)
  • 对我来说(在Windows 10上),我右键单击右下角的wifi图标,单击“打开网络和Internet设置”,然后单击“更改适配器选项”,然后右键单击我用于互联网的当前适配器(我的wifi中的wifi)案例),单击属性,转到共享选项卡,单击“允许其他网络用户通过此计算机的互联网连接进行连接”,然后从下拉列表中选择 vEthernet (DockerNAT) 或与您的计算机等效的任何内容 (2认同)