简体   繁体   English

.Net App in Docker - Startup Can't Find Azure App Configuration

[英].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文件的目录。 Set optional 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.

相关问题 从 .NET 核心 2.2 迁移到 .NET 5 后,应用程序在部署到 azure 应用程序服务后无法启动 - 启动超时 - After migration from .NET core 2.2 to .NET 5 the application won't start after deploying to azure app service - startup timeout 在 Kudu 中找不到 Azure webjob 的 App.config - Can't find Azure webjob's App.config in Kudu Azure 应用服务无法启动 w/ Azure 容器注册表拉取 - Docker 容器 - 找不到文件 - 与 Docker 集线器一起使用 - Azure App Service Fails to Start w/ Azure Container Registry Pull - Docker Container - Can not Find File - Works with Docker Hub Azure 应用服务启动命令在 docker 容器上不起作用 - Azure App Service startuop command isn't working on a docker container ASP.net 核心 docker https on Azure 应用服务容器 - ASP.net core docker https on Azure App Service Containers 刷新Azure 基于Label的App配置 - Refreshing Azure App Configuration Based on Label Key和Label对Azure App配置的限制 - Limitations of Key and Label for Azure App Configuration 无法更新 Azure App 中的配置设置 - Unable to Update Configuration Settings in Azure App 如何读取Service Fabric Azure App Configuration ASP.NET Core Stateless Web API? - How to read the Azure App Configuration in Service Fabric ASP.NET Core Stateless Web API? 无法使用 xcode 方案和配置构建 react-native 应用程序 - Can't build react-native app with xcode scheme and configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM