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.
CodePudding user response:
The Dockerfile
needs to explicitly specify with the ARG
instruction:
ARG USERNAME
ARG GITHUB_TOKEN