1

I'm quite new in Docker word and I would like to pass arguments to my script from docker run. My C# code looks like:

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello: " + args[0]);
        }
    }

And my Docker file is the following:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
WORKDIR /app

COPY MediumDemo.csproj .
RUN dotnet restore MediumDemo.csproj

COPY . .
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/runtime:3.1 as runtime
WORKDIR /app
COPY --from=build /app/out ./

ENTRYPOINT ["dotnet", "Demo.dll"]
DerGeza
  • 13
  • 1
  • 3
  • Does this answer your question? [How to pass command line arguments to a dotnet dll in a Docker image at run time?](https://stackoverflow.com/questions/54654987/how-to-pass-command-line-arguments-to-a-dotnet-dll-in-a-docker-image-at-run-time) – Crowcoder Jun 23 '20 at 15:40

1 Answers1

1

This is old, but for anyone who might be looking at it, you have to combine ENTRYPOINT with CMD in your Dockerfile, as follows:

ENTRYPOINT [ "dotnet", "Demo.dll" ]
CMD [ "arg0" ]

Then run it:

docker run -it Demo myarg

And you should see the output you expect.

Aaron Haspel
  • 140
  • 10