如何在使用 Docker 时为 NuGet 配置代理?

Raj*_*ade 6 c# nuget docker .net-core dockerfile

我在构建 docker 镜像时使用 dotnet:2.1-sdk 作为一个包。RUN dotnet restore 命令失败并出现以下错误:

**error : Unable to load the service index for source https://api.nuget.org/v3/index.json.**

**error :   A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond**

**The command 'cmd /S /C dotnet restore' returned a non-zero code: 1**
Run Code Online (Sandbox Code Playgroud)

这是代理的问题,因为如果我绕过公司网络并连接到我的个人网络,它就可以工作。

我还尝试将 NuGet.Config 文件放在源目录中,并尝试将其复制到 WORKDIR。没有任何效果。

请让我知道在 docker 环境中设置“代理”以使 dotnet 恢复工作的过程。

谢谢。

ltu*_*ska 6

在这里检查我的答案。

基本上,您应该通过添加构建参数来指示 docker 构建环境使用代理,例如:

docker build --build-arg HTTP_PROXY=<proxy URL> --build-arg HTTPS_PROXY=<proxy URL> -t <application name>
Run Code Online (Sandbox Code Playgroud)