We have a .NET Core project in Visual Studio (2017) that has Docker support added. Our project relies on environment variables to configure itself at start up. As we understand it, in order to pass environment variable values to a container you specify them as arguments to the docker run
command using -e
.
When you run the containerized version of the project from Visual Studio by selecting the Docker profile, we noticed that Visual Studio executes a docker run
command. However, we've not been able to figure out how to get Visual Studio to include our environment variable values when it runs the container.
Is there a way to tell Visual Studio to pass our environment variable values to a container it runs?
Note that we do not want to specify the environment variable values in the image since the values will change depending on where it is deployed to.
You can choose to include additional environment files to be passed to the docker run
command by adding the following property to your .csproj file:
<DockerfileRunEnvironmentFiles>your_env_file.env</DockerfileRunEnvironmentFiles>
I have a command line .NET Core application that consumes a secret in the input arguments, like
mycli -ACCOUNT_KEY abcdef123=
. For debugging purposes, I don't want to have this value in my source countrol, so I set it as an environment variable on my system that I'm then passing in the command line arguments. This is what I did:
In the system environment variables:
In the project settings:
In the .csproj file:
In the .gitignore:
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