Docker Run 设置环境变量

Docker Run

We can then override the environment variables set in the Docker file when running the image by using the -e flag:

Docker run -e "EmailServer=192.168.0.1" myimage

 

对应.netcore应用程序,设置 ASPNETCORE_ENVIRONMENT 环境变量为自定义的值,就会寻找对应的配置文件,默认不设置会加载appsettings.json

Docker run -e "ASPNETCORE_ENVIRONMENT=development" myimage

注意:设置环境变量一定要先放到 run 后,否则不起作用,这个时我踩过的坑。

参考:

https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/environments?view=aspnetcore-2.2

https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/host/web-host?view=aspnetcore-2.2#set-up-a-host

https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/index?view=aspnetcore-2.2#json-configuration-provider

https://www.scottbrady91.com/Docker/ASPNET-Core-and-Docker-Environment-Variables

https://andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/

http://www.cnblogs.com/dudu/p/6985313.html

 

转载于:https://www.cnblogs.com/lishidefengchen/p/10688259.html

你可能感兴趣的:(Docker Run 设置环境变量)