1

I am running my webapi project in docker container and I am unable to use environment variable set on my machine. Can I use System's Environment variable on running container. Thanks In Advance

var env = Environment.ExpandEnvironmentVariables("kubes");
var env2 = Environment.GetEnvironmentVariable("kubes");
hassan.ef
  • 1,300
  • 2
  • 11
  • 19
ISK
  • 85
  • 1
  • 9

1 Answers1

3

The environment variables on the host machine are not available inside the Docker container, but it's possible to pass them in when starting the container:

docker run -e "deep=purple" -e today my-image

-e will set an environment variable inside the container. In the example the first option will set the environment variable deep with the value purple, while the second will set the variablle today with same value as the today variable has on the host machine. E.g. if today is set on your machine, it will also be set inside the container with the same value; it effectively passes it on.

Docker docs: click

Jon G Stødle
  • 3,844
  • 1
  • 16
  • 22
  • Can i set this option in my docker file? – ISK May 23 '19 at 09:06
  • You'll have to pass in the environment variables as build args and then assign them with ENV. Have a look at this answer: https://stackoverflow.com/a/34600106/1339804 – Jon G Stødle May 23 '19 at 17:18