【发布时间】:2023-03-08 15:48:01
【问题描述】:
我正在尝试运行 .NET Core dockerfile,但在 dotnet restore 中不断出现错误。我在 Linux 容器中运行它。我尝试在 Windows 容器中运行它,但在 COPY 命令期间出现错误。
我有一个 docker compose 文件,它从子文件夹加载 .NET Core dockerfile。我在 Powershell 中运行“docker-compose up”。构建过程进入 dotnet restore 步骤并抛出此错误:
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : Unable to load the service index for source http://192.168.30.2:8080/tfs/DefaultCollection/_packaging/api-library/nuget/v3/index.json. [/Portal.API/Portal.Api.csproj]
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : GSSAPI operation failed with error - Unspecified GSS failure. Minor code may provide more information (SPNEGO cannot find mechanisms to negotiate). [/Portal.API/Portal.Api.csproj]
我尝试根据 Stackoverflow 帖子更新 Visual Studio 中的 devenv.exe.config 文件:https://stackoverflow.com/a/47837720/2026659
更新 devenv.exe.config 后,我得到了这个略有不同的错误(也包括整个构建输出):
Step 1/9 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS api-env
---> cef7866e800b
Step 2/9 : WORKDIR /Portal.API
---> Using cache
---> 80eea76dc2a0
Step 3/9 : COPY ./Portal.API/Portal.Api.csproj .
---> Using cache
---> 0739924c5ebf
Step 4/9 : COPY ./Portal.API/NuGet.config .
---> f1a514456db0
Step 5/9 : RUN dotnet restore
---> Running in 9d4a8f5d6239
Restore completed in 8.15 sec for /Portal.API/Portal.Api.csproj.
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : Unable to load the service index for source http://192.168.30.2:8080/tfs/DefaultCollection/_packaging/api-library/nuget/v3/index.json. [/Portal.API/Portal.Api.csproj]
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : Connection refused [/Portal.API/Portal.Api.csproj]
ERROR: Service 'portal.api' failed to build: The command '/bin/sh -c dotnet restore' returned a non-zero code: 1
更新:我的一些 NuGet 包托管在我通过 VPN 访问的本地网络上的专用服务器上。我使用 Windows Active Directory 登录我的工作笔记本电脑,我认为这些凭据用于访问私有服务器。
更新 2:我在 NuGet.config 中添加了登录凭据,如下所示:
...
<packageSourceCredentials>
<api-library>
<add key="Username" value="username" />
<add key="ClearTextPassword" value="password" />
</api-library>
</packageSourceCredentials>
</configuration>
现在在 docker 容器中运行 dotnet restore 时出现不同的错误:
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : Unable to load the service index for source http://192.168.30.2:8080/tfs/DefaultCollection/_packaging/api-library/nuget/v3/index.json. [/Portal.API/Portal.Api.csproj]
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(123,5): error : GSSAPI operation failed with error - An invalid name was supplied (Configuration file does not specify default realm).
在进行更多的谷歌搜索之后,我认为我需要以不同的方式传递登录凭据,可能使用个人访问令牌,如 GitHub 帖子中的:https://github.com/microsoft/artifacts-credprovider/issues/63
我不知道该怎么做。
【问题讨论】:
-
您的项目是否依赖于由
192.168.30.2:8080上的私有 nuget 服务器托管的 NuGet 包?看起来 nuget 正试图从容器 inside 访问该服务器并且无法访问。 (我不是 Docker 网络专家,所以我不确定这是否符合预期) -
它说连接被拒绝,所以从容器内部到达不是问题。从他连接到它的任何地方,在
192.168.30.2的端口8080上没有任何监听。您可以通过telnet 192.168.30.2 8080确认。 -
是的,它是托管在我工作的本地网络上的私人服务器。我通过 VPN 访问它。
-
@mdailey77 我也在尝试处理同样的情况。有什么对你有用吗?
-
@lquery 我忘记了这个问题。我切换到 Windows 容器并且 dotnet restore 工作。
标签: docker .net-core dockerfile