dockerfile中nuget源加载失败Retrying 'FindPackagesByIdAsync' for source 'xxx'

问题描述:最近jenkins打包总是提示微软源加载不到

Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/microsoft.extensions.primitives/index.json'.
An error occurred while sending the request.

解决方案:dockerfile中添加国内源,改用华为源就哦了,完整dockerfile文件如下:

#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/aspnet:6.0 AS base
#RUN sed -i 's@/archive.ubuntu.com/@/mirrors.aliyun.com/@g' /etc/apt/sources.list
RUN sed -i 's@dl-cdn.alpinelinux.org@mirrors.ustc.edu.cn@g' /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update
RUN apt-get -y install fonts-wqy-zenhei && apt-get clean &&  fc-cache -fv
WORKDIR /app
EXPOSE 8888

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ./ /src
RUN dotnet nuget remove source nuget.org
RUN dotnet nuget add source https://repo.huaweicloud.com/repository/nuget/v3/index.json -n hw_nuget
RUN dotnet restore "./xxx.Mvc/xxx.Mvc.csproj"
COPY . .
WORKDIR "/src/xxx.Mvc/."
RUN dotnet build "xxx.Mvc.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "xxx.Mvc.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "xxx.Mvc.dll"]

 

posted @ 2024-10-17 23:11  wangbg  阅读(34)  评论(0编辑  收藏  举报