Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget command fails in docker file but not when run manually

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
like image 351
Vaccano Avatar asked Jul 02 '19 22:07

Vaccano


People also ask

What does T flag do with docker run?

The -t (or --tty) flag tells Docker to allocate a virtual terminal session within the container. This is commonly used with the -i (or --interactive) option, which keeps STDIN open even if running in detached mode (more about that later).

What is docker flag run?

The docker run command provides a flag that will copy the volumes from one or more containers to the new container. The flag --volumes-from can be set multiple times to specify multiple source containers.

Can Dockerfile run multiple command prompts?

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect. If CMD is used to provide default arguments for the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be specified with the JSON array format.

What is Dockerfile Run command?

RUN - RUN instruction allows you to install your application and packages required for it. It executes any commands on top of the current image and creates a new layer by committing the results. Often you will find multiple RUN instructions in a Dockerfile.


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
like image 153
arnonuem Avatar answered Oct 16 '22 21:10

arnonuem