2

Is there a way get NuGet on a linux based Docker image?

I tried this:

ARG PAT

FROM microsoft/dotnet:sdk AS build
WORKDIR /app

COPY src/IdentityServer/ ./

# the annoying NuGet installation
RUN wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get install nuget
RUN nuget sources add -name yyyy-source https://xxxx.pkgs.visualstudio.com/_packaging/yyyy/nuget/v3/index.json -username dummy -password ${PAT}
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:aspnetcore-runtime AS runtime
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT ["dotnet", "IdentityServer.dll"]

I get this:

Step 5/13 : RUN wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
 ---> Using cache
 ---> db337597f4fe
Step 6/13 : RUN dpkg -i packages-microsoft-prod.deb
 ---> Running in c361881586a3
Selecting previously unselected package packages-microsoft-prod.
(Reading database ... 12109 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb ...
Unpacking packages-microsoft-prod (1.0-3) ...
Setting up packages-microsoft-prod (1.0-3) ...
Removing intermediate container c361881586a3
 ---> 6a56d436e5da
Step 7/13 : RUN apt-get install nuget
 ---> Running in c47705590796
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package nuget
The command '/bin/sh -c apt-get install nuget' returned a non-zero code: 100

but some people have success getting that NuGet package installed on Linux: How to install NuGet from command line on linux

mikebz
  • 3,277
  • 8
  • 37
  • 50
  • 1
    Had you tried updating repository cache in between via `apt-get update` (after installing packages-microsoft-prod.deb) ? Docker does not perform much magic itself internally – agg3l Nov 17 '18 at 02:39

1 Answers1

2

I see the only reason you're trying to get nuget.exe is to add credentials. This page in the docs has links on how to authenticate to Azure Devops using the dotnet cli. Your use case falls into the "otherwise" sentence of the CI builds section, so you can use an environment variable to specify your PAT. Therefore, you don't actually need nuget.

zivkan
  • 12,793
  • 2
  • 34
  • 51
  • yes that is the right solution. Thank you! It's not simple and I wish the authors of the plugin had a docker section, but... it can be figured out. – mikebz Nov 20 '18 at 21:34
  • docker docs also suggest that the `ARG PAT` is available up to an including the `FROM ...` but not after the `FROM ...`. If your use-case, the `ARG PAT` should be after the `FROM ...`. – Jesse Chisholm May 20 '21 at 16:16