We are using microservices approach to build our product. We are using some projects which each uses docker-compose to run. The problem is that in development environment, if we want to change codes in multiple projects and test developed codes, we must run projects separately and link them together manually.
Now we want to create a development kit which clones projects and runs them together and handles links. Can docker-compose handle multiple docker-compose file? If not is there any sufficient tool to do that for us? Or is there any recommended approach for our goal?
EDIT: For example we have two projects: PROJECT_A and PROJECT_B. Each one has its own docker-compose.yml and each one needs postgresql to run. We have docker-compose.yml in PROJECT_A like this:
db:
image: postgres:9.4
ports:
- "5432"
project_a:
build: .
command: python2.7 main.py
links:
- db
And we have docker-compose.yml in PROJECT_B like this:
db:
image: postgres:9.4
ports:
- "5432"
project_b:
build: .
command: python2.7 main.py
links:
- db
Each project can run separately and works fine. But if we want to change the api between PROJECT_A and PROJECT_B we need to run both projects and link them together to test our code. Now we want to write a development kit project which can run both projects and link them if needed. What is the best approach to do this?
You can do this by combining services from multiple files using the extends
feature of docker-compose
. Put your projects in some well-defined location, and refer to them using relative paths:
../
├── foo/
│ └── docker-compose.yml
└── bar/
└── docker-compose.yml
base:
build: .
foo:
extends:
service: base
links:
- db
db:
image: postgres:9
If you wanted to test this project by itself, you would do something like:
sudo docker-compose up -d foo
Creating foo_foo_1
foo:
extends:
file: ../foo/docker-compose.yml
service: base
links:
- db
bar:
build: .
extends:
service: base
links:
- db
- foo
db:
image: postgres:9
Now you can test both services together with:
sudo docker-compose up -d bar
Creating bar_foo_1
Creating bar_bar_1