docker构建含私有包源的项目包还原失败处理
因为项目中一些原因需要临时引用一下本地的包,但是在生成docker镜像时donet restore出现了问题,提示不能再nuget.org中找到包,故在此记录一下处理。
解决方法如下:
首先添加nuget.config文件,内容如下:
下面展示一些 内联代码片
。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<!--这里添加自己的包地址-->
<add key="Package source" value="xxx" />
</packageSources>
</configuration>
然后修改dockerfile文件将nuget.config和本地包源文件复制到同源目录下:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["nuget.config", "."]
COPY ["本地包源地址", "."]
COPY ["xx.csproj", "."]
RUN dotnet restore "./xx.csproj" --configfile "nuget.config"
COPY . .
WORKDIR "/src/."
RUN dotnet build "xx.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "xx.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "xx.dll"]
至此就可以处理docker镜像构建含有本地包源包还原失败的问题了
参考文章:https://blog.csdn.net/xtjatswc/article/details/108192083?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_title~default-8.no_search_link&spm=1001.2101.3001.4242