[英].Net App in Docker - Startup Can't Find Azure App Configuration
I'm working to move my app from an app service into a docker container.我正在努力将我的应用程序从应用程序服务移动到 docker 容器中。 I've added a dockerfile and other standard docker requirements.
我添加了 dockerfile 和其他标准 docker 要求。
My app previously had been using Azure App Configuration to provide a good portion of the configuration settings during startup.我的应用程序以前一直使用 Azure 应用程序配置在启动期间提供大部分配置设置。
Here's the key part of my Startup.CS这是我的 Startup.CS 的关键部分
When I run this typically, it gets the connection string from the Environment settings, and calls out to the service and retrieves the configuration.当我通常运行它时,它会从环境设置中获取连接字符串,调用服务并检索配置。
The environment settings are being found in the Docker startup.在 Docker 启动中可以找到环境设置。 However, the service call part isn't working and none of those settings are being made available.
但是,服务调用部分不起作用,并且这些设置均不可用。
How can I enable this?我怎样才能启用它?
The recommended way to read the Environment variables and Connection Strings is below:读取环境变量和连接字符串的推荐方法如下:
var Appconfig = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
//Reading config values from local.settings.json
var appSetValue = Appconfig["MyCustomSetting"];
//Reading Application Settings
var value = Environment.GetEnvironmentVariable("MyCustomSetting");
//Reading Connection Strings
var mycusString = Appconfig.GetConnectionString("MyCustomSetting");
FunctionAppDirectory sets the directory to find your
local.settings.json
file.FunctionAppDirectory设置用于查找
local.settings.json
文件的目录。 Setoptional
to true because we won't have the file when we deploy.将
optional
设置为 true 因为我们在部署时不会拥有该文件。 AddEnvironmentVariables will pick up both App Settings and Connection Strings from Azure settings.AddEnvironmentVariables将从 Azure 设置中获取应用程序设置和连接字符串。 Refer here
参考这里
Refer Azure Function Configuration and Secrets Management on Startup.cs参考Azure Function Startup.cs 上的配置和机密管理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.