继承或嵌套与 docker compose [英] Inheritance or nesting with docker compose

查看:38
本文介绍了继承或嵌套与 docker compose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动我们的应用程序的最佳方式是使用我们提供的 docker compose.docker-compose 以正确的配置启动所有服务.

The best way to start our application is by using a docker compose we provide. The docker-compose starts all the services with the right configuration.

现在我们想提供一个 docker-compose 应用程序在不同的后端运行.在这个组合中,10 个服务中有 8 个相同,2 个不同.

Now we would like to provide a docker-compose where the application runs with a different backend. In this compose 8 out 10 services are the same and 2 are different.

如何在不重复代码的情况下实现这一目标?我看到一个服务可以从另一个 docker-compose 文件扩展一个服务,但是这仍然需要在两个文件中列出所有 10 个服务.

How to achieve this without code duplication? I see that a service can extend a service from another docker-compose file, however this would still require to list all the 10 services in both files.

推荐答案

使用 docker-compose 1.6 这应该是可能的.

With docker-compose 1.6 this should be possible.

用你的公共服务创建一个docker-compose.yml:

Create a docker-compose.yml with your common services:

service01:
  image: image01
  links:
    - service02

service02:
  image: image02

还有第二个文件,docker-compose.prod.yml,其中包含您的独特服务:

And a second file, docker-compose.prod.yml with your unique services:

service03:
  image: image03
  links:
    - service02

现在您可以使用以下命令启动服务 01、02 和 03:

Now you can start service 01, 02 and 03 with this command:

docker-compose -f docker-compose.yml -f docker-compose.prod.yml

更多信息参见官方文档:https://docs.docker.com/compose/extends/#multiple-compose-文件

For more information, see the official documentation: https://docs.docker.com/compose/extends/#multiple-compose-files

这篇关于继承或嵌套与 docker compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆