1

I have three different projects, ProjectA depends on ProjectB, which in turn depends on ProjectC.

Assume you want to develop only ProjectC, so I want to use a setup with one container only at its runtime.

ProjectB needs ProjectC, so I have to define a docker-compose with two images.

ProjectA then again needs both ProjectB and ProjectC, so I fear I have to either duplicate a lot in the each docker-compose.yml file the longer the dependency chain gets.

I know I can link external images in a docker-compose.yml, yet this means more manual setup, as I have to checkout each project and run docker-compose.yml in each of them.

Basically I wonder how I can manage a docker-compose setup for a microservice architecture.

For the lack of a better phrase: Can I extend docker-compose.yml files?

kenorb
  • 137,499
  • 74
  • 643
  • 694
k0pernikus
  • 50,568
  • 57
  • 198
  • 317
  • In short I think the answer is currently _no_. `extends` is very limited (see https://github.com/docker/compose/issues/1617 https://github.com/docker/compose/issues/3220) and there is no `includes`/ `path` or multi-file compose yet (see https://github.com/docker/compose/issues/318 and https://github.com/docker/compose/issues/3322) – KCD Jun 14 '16 at 22:53
  • Related: [How to extend service in Docker Compose V3?](https://stackoverflow.com/q/52587643/55075) – kenorb Mar 07 '19 at 22:36

2 Answers2

2

You can extend services in docker-compose.yml from another YAML file. Just use extends key in your docker-compose.yml.

For example:

projectC.yml

webapp:
 build: .
 environment:
   - KEY=VALUE
 ports:
   - "8000:8000"

projectB.yml

web:
  extends:
    file: projectC.yml
    service: webapp
Lauri
  • 4,028
  • 3
  • 17
  • 17
  • 1
    The current extend system seems to be quite restrictive as `services with 'links' cannot be extended`. [There's an issue for this on github](https://github.com/docker/compose/issues/1617). – k0pernikus Oct 09 '15 at 10:04
2

The next release (1.5.0) will support a way to extend a composition (see https://github.com/docker/compose/pull/2051). It is in master now if you want to try it out.

I think what you're describing is pretty close to this proposal https://github.com/docker/compose/issues/318

dnephin
  • 22,719
  • 9
  • 50
  • 40