dotnet恢复在本地工作,但在构建Docker容器时失败 [英] dotnet restore works locally but fails when building Docker container

查看:695
本文介绍了dotnet恢复在本地工作,但在构建Docker容器时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 dotnet classlib -lang f#-o hello-docker 创建新的控制台应用程序,将 cd 放入目录,然后运行 dotnet restore ,一切都会按预期进行。

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.

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

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" ]

并运行 docker build。,它失败进入 nuget.org 并显示以下消息:

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):错误:无法加载源 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

/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

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

Why can I restore locally, but not inside the Docker container?

推荐答案

进入我的网络适配器的属性/共享,并与hyper-v / docker开关共享...以为它被称为nat之类的东西。

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.

这篇关于dotnet恢复在本地工作,但在构建Docker容器时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆