❔ Docker + .NET [open / unresolved]

Hey all, I want to build a docker container which consumes a NuGet Package from a nuget feed behind a proxy. The problem is, it does not work:
4 Replies
Robin Lindner
Robin LindnerOP2y ago
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build

ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG AZURE_DEVOPS_ACCESS_TOKEN

ENV HTTP_PROXY ${HTTP_PROXY}
ENV HTTPS_PROXY ${HTTPS_PROXY}
ENV AZURE_DEVOPS_ACCESS_TOKEN ${AZURE_DEVOPS_ACCESS_TOKEN}

WORKDIR /src
COPY ["src/WIS.WebAPI.SharedServices/WIS.WebAPI.SharedServices.csproj", "src/WIS.WebAPI.SharedServices/"]
COPY ["src/WIS.WebAPI.ApplicationServices/WIS.WebAPI.ApplicationServices.csproj", "src/WIS.WebAPI.ApplicationServices/"]
COPY ["src/WIS.WebAPI.DataAccess/WIS.WebAPI.DataAccess.csproj", "src/WIS.WebAPI.DataAccess/"]
COPY ["src/WIS.WebAPI.Models/WIS.WebAPI.Models.csproj", "src/WIS.WebAPI.Models/"]
COPY ["src/WIS.StatusCodes/WIS.SharedServices.StatusCodes.csproj", "src/WIS.StatusCodes/"]
COPY ["src/WIS.WebAPI.Enums/WIS.WebAPI.SharedServices.Enums.csproj", "src/WIS.WebAPI.Enums/"]
COPY ["src/WIS.WebAPI.SharedServices.DTOs/WIS.WebAPI.SharedServices.DTOs.csproj", "src/WIS.WebAPI.SharedServices.DTOs/"]
COPY ["src/WIS.WebAPI.Validators/WIS.WebAPI.Validators.csproj", "src/WIS.WebAPI.Validators/"]

RUN dotnet nuget add source -n wisfeed -u unused -p ${AZURE_DEVOPS_ACCESS_TOKEN} --valid-authentication-types basic --store-password-in-clear-text "https://myFeed/.../nuget/v3/index.json" \
&& dotnet nuget enable source wisfeed
RUN echo ${HTTP_PROXY} - ${AZURE_DEVOPS_ACCESS_TOKEN}
RUN dotnet restore "src/WIS.WebAPI.SharedServices/WIS.WebAPI.SharedServices.csproj"
COPY . .
WORKDIR "/src/src/WIS.WebAPI.SharedServices"
RUN dotnet build "WIS.WebAPI.SharedServices.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WIS.WebAPI.SharedServices.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WIS.WebAPI.SharedServices.dll"]
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build

ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG AZURE_DEVOPS_ACCESS_TOKEN

ENV HTTP_PROXY ${HTTP_PROXY}
ENV HTTPS_PROXY ${HTTPS_PROXY}
ENV AZURE_DEVOPS_ACCESS_TOKEN ${AZURE_DEVOPS_ACCESS_TOKEN}

WORKDIR /src
COPY ["src/WIS.WebAPI.SharedServices/WIS.WebAPI.SharedServices.csproj", "src/WIS.WebAPI.SharedServices/"]
COPY ["src/WIS.WebAPI.ApplicationServices/WIS.WebAPI.ApplicationServices.csproj", "src/WIS.WebAPI.ApplicationServices/"]
COPY ["src/WIS.WebAPI.DataAccess/WIS.WebAPI.DataAccess.csproj", "src/WIS.WebAPI.DataAccess/"]
COPY ["src/WIS.WebAPI.Models/WIS.WebAPI.Models.csproj", "src/WIS.WebAPI.Models/"]
COPY ["src/WIS.StatusCodes/WIS.SharedServices.StatusCodes.csproj", "src/WIS.StatusCodes/"]
COPY ["src/WIS.WebAPI.Enums/WIS.WebAPI.SharedServices.Enums.csproj", "src/WIS.WebAPI.Enums/"]
COPY ["src/WIS.WebAPI.SharedServices.DTOs/WIS.WebAPI.SharedServices.DTOs.csproj", "src/WIS.WebAPI.SharedServices.DTOs/"]
COPY ["src/WIS.WebAPI.Validators/WIS.WebAPI.Validators.csproj", "src/WIS.WebAPI.Validators/"]

RUN dotnet nuget add source -n wisfeed -u unused -p ${AZURE_DEVOPS_ACCESS_TOKEN} --valid-authentication-types basic --store-password-in-clear-text "https://myFeed/.../nuget/v3/index.json" \
&& dotnet nuget enable source wisfeed
RUN echo ${HTTP_PROXY} - ${AZURE_DEVOPS_ACCESS_TOKEN}
RUN dotnet restore "src/WIS.WebAPI.SharedServices/WIS.WebAPI.SharedServices.csproj"
COPY . .
WORKDIR "/src/src/WIS.WebAPI.SharedServices"
RUN dotnet build "WIS.WebAPI.SharedServices.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WIS.WebAPI.SharedServices.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WIS.WebAPI.SharedServices.dll"]
@echo off
docker build . -t sharedservices:0.1.0 -f . --build-arg HTTP_PROXY=%HTTP_PROXY% --build-arg HTTPS_PROXY=%HTTPS_PROXY% --build-arg AZURE_DEVOPS_ACCESS_TOKEN=%AZURE_DEVOPS_ACCESS_TOKEN%
@echo off
docker build . -t sharedservices:0.1.0 -f . --build-arg HTTP_PROXY=%HTTP_PROXY% --build-arg HTTPS_PROXY=%HTTPS_PROXY% --build-arg AZURE_DEVOPS_ACCESS_TOKEN=%AZURE_DEVOPS_ACCESS_TOKEN%
#20 237.2 /src/src/WIS.WebAPI.ApplicationServices/WIS.WebAPI.ApplicationServices.csproj : error NU1301: Unable to load the service index for source https://myfeed/.../nuget/v3/index.json. [/src/src/WIS.WebAPI.SharedServices/WIS.WebAPI.SharedServices.csproj]
#20 237.2 /src/src/WIS.WebAPI.ApplicationServices/WIS.WebAPI.ApplicationServices.csproj : error NU1301: Unable to load the service index for source https://myfeed/.../nuget/v3/index.json. [/src/src/WIS.WebAPI.SharedServices/WIS.WebAPI.SharedServices.csproj]
Have you ever worked behind a corporate proxy with NuGet, if so how?
happyspider
happyspider2y ago
Have you tried to run dotnet nuget add source -n wisfeed -u unused -p ${AZURE_DEVOPS_ACCESS_TOKEN} --valid-authentication-types basic --store-password-in-clear-text "https://myFeed/.../nuget/v3/index.json" \ && dotnet nuget enable source wisfeed dotnet restore "src/WIS.WebAPI.SharedServices/WIS.WebAPI.SharedServices.csproj" on your machine with your proxy disabled? You could also try RUN curl https://myFeed/.../nuget/v3/index.json in your container
Robin Lindner
Robin LindnerOP2y ago
On the machine it works Does only work with curl -x http://myproxy:3128 --proxy-user username@password -L https://myFeed/.../nuget/v3/index.json
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server