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

9

在构建Docker镜像时,我使用了dotnet:2.1-sdk软件包。 运行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**

这是一个代理问题,因为如果我绕过企业网络并连接到我的个人网络,就可以正常工作。

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

请告诉我如何设置“代理”,以便在docker环境中使用dotnet restore。

谢谢。

1个回答

6

请查看我的答案这里

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接