【问题标题】:Getting error during dotnet restore in docker container在 docker 容器中进行 dotnet 还原期间出现错误
【发布时间】: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


【解决方案1】:

@greektreat;谢谢!这解决了我几天来一直在努力解决的问题。在 docker build 期间,我的私人提要超时。添加基本​​身份验证解决了我的问题。

fyi 我更新的 docker 文件声明; 运行 dotnet nuget add source "$feed" -n PrivateFeed -u docker -p "$pat" --store-password-in-clear-text --valid-authentication-types "basic" --configfile nuget.config

【讨论】:

    【解决方案2】:

    对此有很多问题。刚刚发现,dotnet restore 正在尝试使用 NTML,您需要强制它使用基本身份验证,以便 PAT 在 linux 上运行。基于这篇文章https://developercommunity.visualstudio.com/t/azure-artifacts-nuget-feed-gives-error-during-rest/711941

    在你需要添加的地方

      <add key="ValidAuthenticationTypes" value="basic" />
    

    例如:

    <packageSourceCredentials>
        <api-library>
            <add key="Username" value="username" />
            <add key="ClearTextPassword" value="password" />
            <add key="ValidAuthenticationTypes" value="basic" />
          </api-library>
      </packageSourceCredentials>
    </configuration>
    

    【讨论】:

      【解决方案3】:

      我能够通过使用 Windows 容器解决此问题。

      【讨论】:

      • 是否再次尝试使用 Linux 容器?我有同样的问题,我不想使用 Windows。
      猜你喜欢
      • 2020-07-12
      • 1970-01-01
      • 2020-09-07
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多