Nuget command fails in docker file but not when run manually

Viewed 278

I am trying to configure a container to run my build. (It is a windows core container.)

When I run a nuget command in the docker file, it fails. But when I connect powershell to the container, it runs fine.

This is the command in question:

nuget sources Add -Name "Common Source" -Source http://CompanyPackages/nuget/Common

I run it from the docker file like this:

RUN nuget sources Add -Name "Common Source" -Source http://CompanyPackages/nuget/Common

And get the following error:

sources: invalid arguments.

However, when I take the container and start it using:

docker run -it agent:v1

Then run the same command inside the container:

nuget sources Add -Name "Common Source" -Source http://CompanyPackages/nuget/Common

The result is:

Package Source with Name: Common added successfully.

What would cause it to fail in the dockerfile and not in the container?

Note:

In case it is useful, here is my full docker file:

 FROM sixeyed/msbuild:netfx-4.5.2-webdeploy AS build-agent
 SHELL ["powershell"]

 RUN nuget sources Add -Name "Common Source" -Source http://CompanyPackages/nuget/Common
1 Answers

I tried it and got it working like this:

If you change the content of your Dockerfile like this:

FROM sixeyed/msbuild:netfx-4.5.2-webdeploy AS build-agent
SHELL ["powershell"]
RUN ["nuget", "sources" , "Add", "-Name", "\"Common Source\"", "-Source" ,"http://CompanyPackages/nuget/common"]

And when you then run docker build -t yourImageName .

You end up with this:

Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM sixeyed/msbuild:netfx-4.5.2-webdeploy AS build-agent
 ---> 0851a5b495a3
Step 2/3 : SHELL ["powershell"]
 ---> Running in 10082a1c45f8
Removing intermediate container 10082a1c45f8
 ---> c00b912c6a8f
Step 3/3 : RUN ["nuget", "sources" , "Add", "-Name", "\"Common Source\"", "-Source" ,"http://CompanyPackages/nuget/common"]
 ---> Running in 797b6c055928
Package Source with Name: "Common Source" added successfully.
Removing intermediate container 797b6c055928
 ---> 592db3be9f8b
Successfully built 592db3be9f8b
Successfully tagged nuget-tester:latest
Related