Docker Run 設置環境變量

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://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/host/web-host?view=aspnetcore-2.2#set-up-a-hostide

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

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

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

相關文章
相關標籤/搜索