Ruby on rails 如何在docker compose中基于RAILS环境启动不同的服务

Ruby on rails 如何在docker compose中基于RAILS环境启动不同的服务,ruby-on-rails,docker-compose,Ruby On Rails,Docker Compose,如何在docker-compose.yaml文件中智能覆盖 I would like to start service-A, service-B, service-C if RAILS_ENV is development I would like to start service-A, service-B, service-D if RAILS_ENV is staging I would like to start service-A, service-B, service-E if RAI

如何在docker-compose.yaml文件中智能覆盖

I would like to start service-A, service-B, service-C if RAILS_ENV is development
I would like to start service-A, service-B, service-D if RAILS_ENV is staging
I would like to start service-A, service-B, service-E if RAILS_ENV is production

我的建议是从脚本中调用docker compose

如果docker-compose.yaml如下所示:

service-C, service-D, service-E are not variants of the same service, but could be completely different containers as well
然后,不要调用
docker compose up
,而是通过检查环境变量RAILS\u ENV来调用执行条件逻辑的脚本,如下所示:

service-C, service-D, service-E are not variants of the same service, but could be completely different containers as well
/start-services.sh
其中脚本定义如下所示:

service-C, service-D, service-E are not variants of the same service, but could be completely different containers as well
#/bin/bash
如果[$RAILS_ENV==“开发”]
然后
docker组合服务-C
elif[$TESTVAR==“暂存”]
然后
docker合成服务-D
elif[$TESTVAR==“生产”]
然后
docker组合服务-E
其他的
出口1
fi

当然,这个实现依赖于unix,但我认为它可以推广到任何操作系统。

我的建议是从脚本调用docker compose

如果docker-compose.yaml如下所示:

service-C, service-D, service-E are not variants of the same service, but could be completely different containers as well
然后,不要调用
docker compose up
,而是通过检查环境变量RAILS\u ENV来调用执行条件逻辑的脚本,如下所示:

service-C, service-D, service-E are not variants of the same service, but could be completely different containers as well
/start-services.sh
其中脚本定义如下所示:

service-C, service-D, service-E are not variants of the same service, but could be completely different containers as well
#/bin/bash
如果[$RAILS_ENV==“开发”]
然后
docker组合服务-C
elif[$TESTVAR==“暂存”]
然后
docker合成服务-D
elif[$TESTVAR==“生产”]
然后
docker组合服务-E
其他的
出口1
fi
当然,此实现依赖于unix,但我认为它可以推广到任何操作系统。

Docker compose有,您可以有:

  • 使用service-A和service-B在docker compose.yml中共享基本配置
  • 用于开发的
    docker compose.override.yml
    中的service-C配置(默认情况下,docker compose应选择此配置)
  • service-E在docker compose.production.yml中配置,并像
    docker-compose-f docker-compose.yml-f docker-compose.production.yml up-d
    
  • 类似于
    docker compose.staging.yml中的service-E
    • Docker compose拥有,您可以拥有:

      • 使用service-A和service-B在docker compose.yml中共享基本配置
      • 用于开发的
        docker compose.override.yml
        中的service-C配置(默认情况下,docker compose应选择此配置)
      • service-E在docker compose.production.yml中配置,并像
        docker-compose-f docker-compose.yml-f docker-compose.production.yml up-d
        
      • 类似于
        docker compose.staging.yml中的service-E

      • service-C
        service-D
        service-E
        对于相同的服务是不同的配置,还是完全不同的配置?请提供更多上下文以避免X-Y问题service-C、service-D、service-E不是同一服务的变体,但也可能是完全不同的容器,如
        service-C
        service-D
        service-E
        相同服务的不同配置,或者是完全不同的配置?请提供更多上下文以避免X-Y问题service-C、service-D和service-E不是同一服务的变体,但也可能是完全不同的容器