首页 > 解决方案 > 使用 ASP.NET Core 中的部分将 docker 机密读入配置

问题描述

我在 Docker 容器中运行 ASP.NET Core 应用程序。我需要将 docker 机密读入配置,但要包含部分。现在我在 Program.cs 中使用类似的东西

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                [...]
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config.AddKeyPerFile(directoryPath: "/run/secrets", optional: true);
                })
                [...]

它工作正常,但以平面结构存储记录Key:'Value'。我想将它们存储在部分中,例如

Section: {
   Key: 'Value'
}

能够为几个使用部分进行设置的包的 appsettings 提供值。

我怎样才能做到这一点?

标签: dockerasp.net-coredocker-secrets

解决方案


推荐阅读