1

I am trying to add a custom NuGet repo to my docker image but I can't set credentials with --build-arg here my dockerfile

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /app
COPY . .
RUN dotnet nuget add source --username $USERNAME --store-password-in-clear-text --password $GITHUB_TOKEN --name notification "https://nuget.github.xxx.com/notification/index.json"
RUN dotnet restore
RUN dotnet publish -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS runtime
WORKDIR /app
COPY --from=build /app/publish /app
ENTRYPOINT ["dotnet", "notification-api.dll"]
EXPOSE 80

I am trying to start build with this command.

docker build --build-arg GITHUB_TOKEN=my_token --build-arg USERNAME=my_user_name -t notification-api . 

I also tried with curly braces like this ${GITHUB_TOKEN} but it keeps failing.

If I hardcode my username and token in dockerfile it works.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Does this answer your question? [How to pass arguments to a Dockerfile?](https://stackoverflow.com/questions/34254200/how-to-pass-arguments-to-a-dockerfile) (specifically this linked section of the Docker docs: https://docs.docker.com/engine/reference/builder/#arg) – Gino Mempin Dec 29 '22 at 12:28

1 Answers1

2

The Dockerfile needs to explicitly specify with the ARG instruction:

ARG USERNAME 
ARG GITHUB_TOKEN
Mureinik
  • 297,002
  • 52
  • 306
  • 350