微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Api net core 中使用 docker 引用卷和环境变量

如何解决如何在 Api net core 中使用 docker 引用卷和环境变量

实际上在带有 net core 的 mi Apigateway 中,我有一个文件夹结构:

enter image description here

在 Program.cs 中,我需要引用像 _pathConfigOcelot 这样的文件配置:

public static void Main(string[] args)
    {
        string _pathConfigOcelot = Environment.GetEnvironmentvariable("OcelotConfigPath");
        CreateHostBuilder(args,_pathConfigOcelot).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args,string pathConfigOcelot) =>
        Host.CreateDefaultBuilder(args)
           .ConfigureAppConfiguration(
                      ic => ic.AddJsonFile(Path.Combine(pathConfigOcelot,"configuration.json")))
            .ConfigureWebHostDefaults(webBuilder => 
            {
                webBuilder.UseStartup<Startup>();
            });

实际上我使用 docker-compose 来使用卷:

services: 
  tresfilos.webapigateway:
  image: ${DOCKER_REGISTRY-}tresfilosapigateway
  build: 
    context: .
    dockerfile: tresfilos.ApiGateway/ApiGw-Base/Dockerfile
  environment: 
   - ASPNETCORE_ENVIRONMENT=Development
   - IdentityUrl=http://identity-api
  ports:
   - "7000:80"
   - "7001:443"
  volumes:
   - ./tresfilos.ApiGateway/Web.Bff:/app/configuration

我不知道在项目中如何使用docker volume like reference for configuration.js,有什么想法吗?

解决方法

我读这个 ./tresfilos.ApiGateway/Web.Bff:/app/configuration 是因为 /app/configuration 是我应用中 ./tresfilos.ApiGateway/Web.Bff 的别名。

所以我想说的是您将文件引用为 /app/configuration/configuration.json

更新:

在 Web.Bff 之后添加 / 可能会有所帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。