Docker Runcss
We can then override the environment variables set in the Docker file when running the image by using the -e
flag:html
Docker run -e "EmailServer=192.168.0.1" myimage
对应.netcore应用程序,设置 ASPNETCORE_ENVIRONMENT 环境变量为自定义的值,就会寻找对应的配置文件,默认不设置会加载appsettings.jsonweb
Docker run -e "ASPNETCORE_ENVIRONMENT=development" myimage
注意:设置环境变量必定要先放到 run 后,不然不起做用,这个时我踩过的坑。
参考:json
https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/environments?view=aspnetcore-2.2app
https://www.scottbrady91.com/Docker/ASPNET-Core-and-Docker-Environment-Variables.net
https://andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/code