使用Docker进行继承或嵌套 [英] Inheritance or nesting with 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-commit 应用程序在不同的后端运行。在这个组合中,有8个10服务是相同的,而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
与您的常用服务:
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
有关更多信息,请参见官方文档:
< a href = https://docs.docker.com/compose/extends/#multiple-compose-files rel = noreferrer> 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进行继承或嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!