[英]Docker - dotnet restore fails connection to private feeds
Calling do.net restore <project>
from my Dockerfile is resulting in a NU1301: Unable to load the service index for source
error.从我的 Dockerfile 调用
do.net restore <project>
会导致NU1301: Unable to load the service index for source
。 I've been going through many of the suggested similar questions and continue to have issues.我一直在经历许多建议的类似问题并继续遇到问题。 Here is as much info about the things I've tried as I can provide:
这是我所能提供的关于我尝试过的事情的尽可能多的信息:
RUN ping google.com
succeeds (so I can reach the inte.net) RUN ping google.com
成功(所以我可以访问 inte.net)nuget.org
feednuget.org
提要上工作得很好RUN curl <nuget_feed_url>
succeeds RUN curl <nuget_feed_url>
成功--verbosity detailed
doesn't provide any other error messages but the one--verbosity detailed
运行 restore 命令不会提供任何其他错误消息,但会提供一条错误消息Here is the section of the Dockerfile in question这是有问题的 Dockerfile 的部分
FROM mcr.microsoft.com/dotnet/aspnet:6.0.13 AS base
# Create dockeruser in base layer
RUN addgroup --system --gid 1000 dockergroup \
&& adduser --system --uid 1000 --ingroup dockergroup --shell /bin/sh dockeruser
WORKDIR /app
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# Arguments are required in each stage in order to get the correct value
WORKDIR /src
COPY ["src/Nucleus.LumberYard.API/", "Nucleus.LumberYard.API/"]
COPY ["./nuget.config", "./nuget.config"]
WORKDIR "/src/Nucleus.LumberYard.API"
#COPY [".editorconfig", "./"]
RUN dotnet restore "Nucleus.LumberYard.API.csproj"
RUN dotnet build "Nucleus.LumberYard.API.csproj" -c Release --no-restore
Environment info环境信息
Based on my understanding you have the following scenario:根据我的理解,您有以下情况:
do.net restore
command targeting one of your csproj
filecsproj
do.net restore
命令do.net restore
command fails because the do.net
cli is unable to talk with your private nuget feed do.net restore
命令失败,因为do.net
cli 无法与您的私有 nuget 提要通信I encountered the very same situation with the project I'm working on.我在从事的项目中遇到了完全相同的情况。 We have a private Nuget feed hosted in Azure Devops and we too had some troubles figuring out how to solve this.
我们有一个私有的 Nuget 提要托管在 Azure Devops 中,我们在解决这个问题时也遇到了一些麻烦。
First of all, let's clarify the root cause of the problem.首先,让我们弄清楚问题的根本原因。 You did the right thing veryfying that you are able to reach the nuget feed from your build machine, via the
curl
command you mentioned.你做了正确的事情,你可以通过你提到的
curl
命令从你的构建机器到达 nuget 提要。 What is actually failing is the authentication between your build machine and the private nuget feed.实际上失败的是您的构建机器和私有 nuget 提要之间的身份验证。
The first thing you need is a personal access token with read permissions for your nuget feed.您首先需要的是个人访问令牌,它具有您的 nuget 提要的读取权限。 You can follow this guide to create the personal access token you need.
您可以按照本指南创建所需的个人访问令牌。
Once you have the token, you need to provide it to the do.net
cli.获得令牌后,您需要将其提供给
do.net
cli。 There are several ways to do so, I'm going to explain the one that worked for us.有几种方法可以做到这一点,我将解释对我们有用的一种。
Instead of adding the nuget source to the nuget.config
file, we registers it via a cli command.我们不是将 nuget 源添加到
nuget.config
文件,而是通过 cli 命令注册它。 I'm quite sure there is a way to do exactly the same thing via the nuget.config
file (see here for more details).我很确定有一种方法可以通过
nuget.config
文件做完全相同的事情(有关更多详细信息,请参见此处)。
This is the cli command we use inside of our docker file:这是我们在 docker 文件中使用的 cli 命令:
RUN dotnet nuget add source https://foo.bar.com/something/nuget/v3/index.json -u "whatever" -p "my-personal-access-token" --store-password-in-clear-text --valid-authentication-types "basic"
Notice that:请注意:
https://foo.bar.com/something/nuget/v3/index.json
is the absolute URL pointing to the index of your private nuget feed https://foo.bar.com/something/nuget/v3/index.json
是绝对 URL 指向您的私人 nuget 提要的索引whatever
whatever
区别,即使在那里放一个随机字符串my-personal-access-token
must be substituted with the personal access token you have created as a first stepmy-personal-access-token
替换为您创建的个人访问令牌Here you can find the full reference for the do.net nuget add source
command.您可以在此处找到
do.net nuget add source
命令的完整参考。
After registering this source with the do.net
cli, you will be able to run your do.net restore
command with no errors.使用
do.net
cli 注册此源后,您将能够无错误地运行do.net restore
命令。
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.