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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM