简体   繁体   English

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

[英]How to configure proxy for NuGet while using Docker?

I am using dotnet:2.1-sdk as a package while building docker image. 我在构建docker镜像时使用dotnet:2.1-sdk作为包。 The RUN dotnet restore command is failing with below errors: 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**

Its an issue with proxy because if I bypass the corporate network and connect to my personal network, it works. 它是代理问题,因为如果我绕过公司网络并连接到我的个人网络,它就可以工作。

I also tried placing the NuGet.Config file the source directory and also tried to copy it to WORKDIR. 我还尝试将NuGet.Config文件放在源目录中,并尝试将其复制到WORKDIR。 Nothing worked. 没有任何效果。

Please let me know the procedure of setting the "Proxy" for making dotnet restore work in the docker environment. 请让我知道在docker环境中设置“代理”以使dotnet恢复工作的过程。

Thanks. 谢谢。

Check my answer here . 在这里查看我的答案。

Basically, you should instruct the docker build environment to use the proxy by adding build arguments like: 基本上,您应该通过添加构建参数来指示docker构建环境使用代理:

docker build --build-arg HTTP_PROXY=<proxy URL> --build-arg HTTPS_PROXY=<proxy URL> -t <application name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM