3

In my docker file, I have this:

FROM microsoft/dotnet:2.0-runtime
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "app.dll"]

and I need to pass an application argument to the app, let's say --argument, so that the app can run inside the container.

So, I know I can run the app locally by doing

dotnet run -- --argument

but I'm stuck at trying to add the --argument to the Dockerfile (or anywhere, I don't know).

I tried adding CMD ["--argument"], CMD ["--", "--argument"]in the Dockerfile, but with no success.

Is it possible to do this?

3
  • Are you sure this one doesn't work? ENTRYPOINT ["dotnet", "app.dll", "argument"] ?? Commented Oct 18, 2017 at 19:04
  • @KostyaK nope, it doesn't Commented Oct 18, 2017 at 19:16
  • Have you tried CMD["dotnet", "app.dll", "argument"] instead of ENTRYPOINT ["dotnet", "app.dll"]? Commented Oct 18, 2017 at 19:53

2 Answers 2

2

I made it work, by adding the argument in the Dockerfile like so:

...
ENTRYPOINT ["dotnet", "app.dll", "--argument"]
...

But I think that this is not an "absolute" solution, i.e., for instance, the argument I needed to add was not for dotnet, but for the app itself; that's why it worked through the command line with the -- switch. Maybe the solutions proposed in the comment section won't work in all scenarios because of this detail.

Sign up to request clarification or add additional context in comments.

Comments

1

I might be late to the party, but recent Microsoft documentation points out how to pass arguments to .NET console app:

docker run -it --rm counter-image 3

3 is the argument. So if you need to pass args array, you just do it after the image name that you want to run.

I think you might already know this, but I think whoever comes to this question should also have some relevant information.

Source: https://learn.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.