Skip to content

Commit fb2fa1b

Browse files
committed
Added demo multiple compose files
1 parent a87ed3a commit fb2fa1b

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Use Multiple Compose files
2+
3+
Using multiple Compose files lets you customize a Compose application for different environments or workflows. This is useful for large applications that may use dozens of containers, with ownership distributed across multiple teams. For example, if your organization or team uses a monorepo, each team may have their own “local” Compose file to run a subset of the application. They then need to rely on other teams to provide a reference Compose file that defines the expected way to run their own subset. Complexity moves from the code in to the infrastructure and the configuration file.
4+
5+
The quickest [merge](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/). However, [merging rules](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/#merging-rules) means this can soon get quite complicated.
6+
7+
Create `compose.yml`
8+
9+
```yml
10+
services:
11+
web:
12+
image: nginx
13+
depends_on:
14+
- db
15+
- cache
16+
17+
db:
18+
image: postgres:latest
19+
20+
cache:
21+
image: redis:latest
22+
```
23+
24+
Create `compose.override.yml`
25+
26+
```yml
27+
services:
28+
web:
29+
volumes:
30+
- 'code:/tmp'
31+
ports:
32+
- 8900:80
33+
environment:
34+
DEBUG: 'true'
35+
36+
db:
37+
ports:
38+
- 5432:5432
39+
environment:
40+
POSTGRES_PASSWORD: password
41+
POSTGRES_USER: admin
42+
43+
cache:
44+
ports:
45+
- 6379:6379
46+
47+
volumes:
48+
code:
49+
50+
```
51+
52+
```bash
53+
docker compose up
54+
```
55+
56+
Now reads by dedfault `compose.override` and applies the updates. Let's say that we want to run in another environment:
57+
58+
Create `compose.staging.yml`
59+
60+
```yml
61+
services:
62+
web:
63+
ports:
64+
- 80:80
65+
environment:
66+
PRODUCTION: 'true'
67+
68+
db:
69+
environment:
70+
POSTGRES_HOST_AUTH_METHOD: trust
71+
72+
cache:
73+
environment:
74+
TTL: '500'
75+
```
76+
77+
```bash
78+
docker compose -f compose.yml -f compose.staging.yml up
79+
```

0 commit comments

Comments
 (0)