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?
}
Passing environment variables using the --env or -e flag The --name option is used to give a name to the container. The --env option is used to pass the environment variable called ENVVARIABLE with a value foobar to the container.
You can use the ARG command inside a Dockerfile to define the name of a parameter and its default value. This default value can also be overridden using a simple option with the Docker build command.
You can do this with a combination of ENTRYPOINT
to set the command, and CMD
to set default options.
Example, for an ASP.NET Core app:
ENTRYPOINT ["dotnet", "app.dll"]
CMD ["argument"]
If you run the container with no command, it will execute this command when the container starts:
dotnet app.dll argument
And the args
array will have one entry, "argument". But you can pass a command o docker run
to override the CMD
definition:
docker run app arg1 arg2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With