I've got a .NET Core project (using visual studio and adding the docker files via the Visual Studio Tools for Docker).
My DockerFile
looks like this:
FROM microsoft/dotnet:1.0.1-core
ARG source=.
WORKDIR /app
COPY $source .
ENTRYPOINT ["dotnet", "MyApp.dll"]
CMD ["arg1", "arg2"]
My question is, how do I pass parameters into the project?
public static void Main(string[] args)
{
// how does `args` get populated?
}
I used environment variables which can be set by docker-compse.yml too
You can do this with a combination of
ENTRYPOINT
to set the command, andCMD
to set default options.Example, for an ASP.NET Core app:
If you run the container with no command, it will execute this command when the container starts:
And the
args
array will have one entry, "argument". But you can pass a command odocker run
to override theCMD
definition:One approach would be to read in environment variables. You would not modify your Dockerfile to do this. Rather, say you run up your container as follows:
All you now need to figure out is how to read the FOO environment variable in your dotnetcore application. I would try the approach documented here: ASP .NET Core read environment variables
VS Tools for Docker appear to silently override CMD and ENTRYPOINT arguments. Please see How to pass command line when debugging docker-compose project in Visual Studio? and https://github.com/Microsoft/DockerTools/issues/75