vpn在docker公司环境中的Linux容器上的dotnet restore错误

问题描述

关于环境的一点背景。 仅在Cisco AnyConnect VPN上工作的公司环境,已设置代理服务器以访问git或Internet,运行带有Linux容器的Docker CE最新版本的Windows笔记本电脑。

我正在尝试使用https://dotnet.microsoft.com/learn/aspnet/microservice-tutorial/docker-image中的微服务示例。 安装了一些nuget软件包以连接到同一Web API中的数据库添加了一种显示数据库记录的方法。在主机计算机中的kestrel,IIS Express和IIS中,在调试和发行模式下均可正常工作。 创建了一个包含以下内容的Docker文件

# https://hub.docker.com/_/microsoft-dotnet-core
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
workdir /source

# copy csproj and restore as distinct layers
copY *.sln .
copY *.csproj .
RUN dotnet restore "ms.sln"

# copy everything else and build app
copY . .
workdir /source
RUN dotnet publish "ms.sln" -c release -o /app --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
workdir /app
copY --from=build /app ./
ENTRYPOINT ["dotnet","ms.dll"]

这是我在命令提示符下运行的构建命令。

docker build --build-arg HTTP_PROXY=http://server:port--build-arg HTTPS_PROXY=http://server:port -t microservice .

当它开始执行dotnet还原时。我收到了我不理解的错误。我什至在docker设置中设置了代理。

[build 5/8] RUN dotnet restore "ms.sln":
#12 0.843   Determining projects to restore...
#12 1.487 /usr/share/dotnet/sdk/3.1.402/NuGet.targets(128,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/source/ms.sln]
#12 1.487 /usr/share/dotnet/sdk/3.1.402/NuGet.targets(128,5): error :   NTLM authentication is not possible with default credentials on this platform. [/source/ms.sln]
------
Failed to solve with frontend dockerfile.v0: Failed to build LLB: executor Failed running [/bin/sh -c dotnet restore "ms.sln"]: runc did not terminate sucessfully  

我已经阅读并尝试过的文章

NuGet behind a proxy

http://codebuckets.com/2020/08/01/nuget-restore-failing-in-docker-container/

https://github.com/moby/moby/issues/24697

Windows containers have no internet access,but Linux containers do - with VPN-Client active on host

解决方法

我在 Win 10 docker 桌面上遇到了同样的问题。 我通过将设置 -> 资源 -> 网络 -> DNS 服务器 -> 手动 DNS 配置 设置为 8.8.8.8 来解决它。

还要确保在 HTTPS_PROXY 和 HTTP_PROXY 中使用代理服务器的 IP 地址而不是 DNS 名称。示例 HTTP_PROXY=http://123.123.123.123:8080

要获取代理服务器的 IP 地址,请在 Chrome 中转到 chrome://net-export/ 并导出文件。在文件中,IP在PROXY变量下可用,搜索相同。