dotnet restore 在本地工作但在构建 Docker 容器时失败 [英] dotnet restore works locally but fails when building Docker container
问题描述
如果我使用 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): error : 发送请求时出错.[/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 restore 在本地工作但在构建 Docker 容器时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!