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.

1

1 Answer 1

2

The Dockerfile needs to explicitly specify with the ARG instruction:

ARG USERNAME 
ARG GITHUB_TOKEN
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.