Reputation: 99
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");
Upvotes: 1
Views: 2354
Reputation: 3904
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
Upvotes: 3