Let's suppose we want to use Docker for building an app as described in https://docs.microsoft.com/en-us/dotnet/core/docker/building-net-docker-images
Dockerfile:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM microsoft/aspnetcore:2.0
LABEL Name=server Version=0.0.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyDemo.dll"]
But if an application uses packages from non default NuGet feeds that require authentication then this won't work - it'll fail on dotnet restore.
So we need to push nuget configuration into Docker image in some way.
It's kinda awkward to do.
It'd be nice if I could pass credentials via cli arguments:
ARG nuget_user
ARG nuget_password
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore --source https://company/api/nuget/nuget-virtual-dev --user $nuget_user --password $nuget_password
Then I'd pass values for nuget_user/nuget_password args via docker build':
docker build -t mydemo --build-arg nuget_user=user1 --build-arg nuget_password=pwd1 .
This is similar to https://github.com/NuGet/Home/issues/6045 which would allow setting passwords for sources in msbuild
@emgarten I think every command that supports the --source option should support user/password as well. It'd make using nuget much easier. Config files are nice but I think it shouldn't be the only option to control behavior.
@emgarten meanwhile could suggest any workaround for restoring packages on Linux?
Please see #6221
Does nuget.config with a clear text password work for you?
closing as duplicate of #6221 once we decide on the right strategy to provide credentials for dotnet commands, then it will cover this scenario as well.
@emgarten Yes, nuget.config with a clear text password works. thanks.
@jainaashish Honestly I don't think it's a duplicate. Yes, I was a bit of panic about impossibility to restore packages on Linux. But specifying credentials via command line is very useful regardless the fact that specifying via config also works. In the first comment I described my use case. Currently I have to keep a special NuGet.Config and copy it into docker image:
COPY NuGet.Config.docker /root/.nuget/NuGet/NuGet.Config
it works but passing creds in runtime via env-var/args/etc would be more handful.
@evil-shrike Sorry I meant to close it as dupe of #6045 which is an uber issue to design a better solution to provide these cred via cli or msbuild properties, etc...
This is something we would need as well as it breaks our build inside Docker...
Most helpful comment
@emgarten Yes, nuget.config with a clear text password works. thanks.
@jainaashish Honestly I don't think it's a duplicate. Yes, I was a bit of panic about impossibility to restore packages on Linux. But specifying credentials via command line is very useful regardless the fact that specifying via config also works. In the first comment I described my use case. Currently I have to keep a special NuGet.Config and copy it into docker image:
it works but passing creds in runtime via env-var/args/etc would be more handful.