How to extend service in Docker Compose V2?

2019-08-11 02:19发布

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?

2条回答
Bombasti
2楼-- · 2019-08-11 02:43

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

查看更多
爷、活的狠高调
3楼-- · 2019-08-11 02:54

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
查看更多
登录 后发表回答