.NET 5 API Docker with internal NuGet package not found

  .net-5, c#, dockerfile, nuget-package

I’m trying to setup a real basic .net 5.0 API in Docker. I’m completely new to Docker so for the most part, I think I have what is needed, but I ran into a snag. I am using an internal NuGet package. I create a NuGet.Config file with the PackageSource listed in there. Now when I run the docker-compose script, it appears to find the NuGet repo, but now it’s saying Authentication denied. I don’t know the companies settings for credentials, but I’m trying to figure out how to do the following:

  1. Create some sort of ApiKey for the NuGet package
  2. Add the reference in NuGet.Config so I don’t have to use personal credentials in the Dockerfile.

If there are any better examples/solutions, please let me know.

This is what I have so far.
NOTE, I am on a Windows 10 machine.

NuGet.Config:

<configuration>
    <packageSources>
      <clear />
      <add key="<KeyName>" value="<URL PATH>/nuget/v3/index.json" />
      <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    </packageSources>
    <packageRestore>
      <add key="enabled" value="True" />
      <add key="automatic" value="True" />
    </packageRestore>
</configuration>

Here is the docker-compse.yml

version: "3"
services:
  democore.api:
    build: .
    ports:
      - "8163:8163"

Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:5.0.102-ca-patch-buster-slim-amd64 AS build
WORKDIR /src
COPY ["DemoCore.Api.sln", "./"]
COPY ["DemoCore.Api.csproj", "./"]
COPY NuGet.Config ./


RUN dotnet restore "DemoCore.Api.csproj"
COPY . .
RUN dotnet build "DemoCore.Api.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "DemoCore.Api.csproj" -c Release -o /app

FROM mcr.microsoft.com/dotnet/sdk:5.0.102-ca-patch-buster-slim-amd64 AS base
WORKDIR /app
EXPOSE 8163

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

When I run this in command prompt, this is the result:

Docker error

Any help would be great.

Source: Dockerfile Questions

LEAVE A COMMENT