Nuget command fails in docker file but not when run manually

Vac*_*ano 8 containers nuget docker dockerfile

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
Run Code Online (Sandbox Code Playgroud)

I run it from the docker file like this:

RUN nuget sources Add -Name "Common Source" -Source http://CompanyPackages/nuget/Common
Run Code Online (Sandbox Code Playgroud)

And get the following error:

sources: invalid arguments.
Run Code Online (Sandbox Code Playgroud)

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

docker run -it agent:v1
Run Code Online (Sandbox Code Playgroud)

Then run the same command inside the container:

nuget sources Add -Name "Common Source" -Source http://CompanyPackages/nuget/Common
Run Code Online (Sandbox Code Playgroud)

The result is:

Package Source with Name: Common added successfully.
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

arn*_*uem 3

我尝试了一下并让它像这样工作:

Dockerfile如果你像这样改变你的内容:

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"]
Run Code Online (Sandbox Code Playgroud)

然后当你跑的时候docker build -t yourImageName .

你最终会得到这样的结果:

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
Run Code Online (Sandbox Code Playgroud)