Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

–build-arg is not working for my docker build

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

The Dockerfile needs to explicitly specify with the ARG instruction:

ARG USERNAME 
ARG GITHUB_TOKEN
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading