You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> When you use multiple Compose files, you must make sure all paths in the
76
-
files are relative to the base Compose file (the first Compose file specified
72
+
## Merging rules
73
+
74
+
- Paths are evaluated relative to the base file. When you use multiple Compose files, you must make sure all paths in the files are relative to the base Compose file (the first Compose file specified
77
75
with `-f`). This is required because override files need not be valid
78
76
Compose files. Override files can contain small fragments of configuration.
79
77
Tracking which fragment of a service is relative to which path is difficult and
80
78
confusing, so to keep paths easier to understand, all paths must be defined
81
79
relative to the base file.
82
80
81
+
>[!TIP]
82
+
>
83
+
> You can use `docker compose config` to review your merged configuration and avoid path-related issues.
84
+
85
+
- Compose copies configurations from the original service over to the local one.
86
+
If a configuration option is defined in both the original service and the local
87
+
service, the local value replaces or extends the original value.
88
+
89
+
- For single-value options like `image`, `command` or `mem_limit`, the new value replaces the old value.
90
+
91
+
original service:
92
+
93
+
```yaml
94
+
services:
95
+
myservice:
96
+
# ...
97
+
command: python app.py
98
+
```
99
+
100
+
local service:
101
+
102
+
```yaml
103
+
services:
104
+
myservice:
105
+
# ...
106
+
command: python otherapp.py
107
+
```
108
+
109
+
result:
110
+
111
+
```yaml
112
+
services:
113
+
myservice:
114
+
# ...
115
+
command: python otherapp.py
116
+
```
117
+
118
+
- For the multi-value options `ports`, `expose`, `external_links`, `dns`, `dns_search`, and `tmpfs`, Compose concatenates both sets of values:
119
+
120
+
original service:
121
+
122
+
```yaml
123
+
services:
124
+
myservice:
125
+
# ...
126
+
expose:
127
+
- "3000"
128
+
```
129
+
130
+
local service:
131
+
132
+
```yaml
133
+
services:
134
+
myservice:
135
+
# ...
136
+
expose:
137
+
- "4000"
138
+
- "5000"
139
+
```
140
+
141
+
result:
142
+
143
+
```yaml
144
+
services:
145
+
myservice:
146
+
# ...
147
+
expose:
148
+
- "3000"
149
+
- "4000"
150
+
- "5000"
151
+
```
152
+
153
+
- In the case of `environment`, `labels`, `volumes`, and `devices`, Compose "merges" entries together with locally defined values taking precedence. For `environment` and `labels`, the environment variable or label name determines which value is used:
154
+
155
+
original service:
156
+
157
+
```yaml
158
+
services:
159
+
myservice:
160
+
# ...
161
+
environment:
162
+
- FOO=original
163
+
- BAR=original
164
+
```
165
+
166
+
local service:
167
+
168
+
```yaml
169
+
services:
170
+
myservice:
171
+
# ...
172
+
environment:
173
+
- BAR=local
174
+
- BAZ=local
175
+
```
176
+
177
+
result:
178
+
179
+
```yaml
180
+
services:
181
+
myservice:
182
+
# ...
183
+
environment:
184
+
- FOO=original
185
+
- BAR=local
186
+
- BAZ=local
187
+
```
188
+
189
+
- Entries for `volumes` and `devices` are merged using the mount path in the container:
190
+
191
+
original service:
192
+
193
+
```yaml
194
+
services:
195
+
myservice:
196
+
# ...
197
+
volumes:
198
+
- ./original:/foo
199
+
- ./original:/bar
200
+
```
201
+
202
+
local service:
203
+
204
+
```yaml
205
+
services:
206
+
myservice:
207
+
# ...
208
+
volumes:
209
+
- ./local:/bar
210
+
- ./local:/baz
211
+
```
212
+
213
+
result:
214
+
215
+
```yaml
216
+
services:
217
+
myservice:
218
+
# ...
219
+
volumes:
220
+
- ./original:/foo
221
+
- ./local:/bar
222
+
- ./local:/baz
223
+
```
224
+
225
+
For more merging rules, see [Merge and override](/reference/compose-file/merge.md) in the Compose Specification.
226
+
83
227
### Additional information
84
228
85
229
- Using `-f` is optional. If not provided, Compose searches the working directory and its parent directories for a `compose.yml` and a `compose.override.yml` file. You must supply at least the `compose.yml` file. If both files exist on the same directory level, Compose combines them into a single configuration.
86
230
87
-
- When you use multiple Compose files, all paths in the files are relative to the first configuration file specified with `-f`. You can use the `--project-directory` option to override this base path.
88
-
89
231
- You can use a `-f` with `-` (dash) as the filename to read the configuration from `stdin`. For example:
90
232
```console
91
233
$ docker compose -f - <<EOF
@@ -129,156 +271,6 @@ relative to the base file.
129
271
Status: Downloaded newer image for postgres:latest
130
272
```
131
273
132
-
## Merging rules
133
-
134
-
Compose copies configurations from the original service over to the local one.
135
-
If a configuration option is defined in both the original service and the local
136
-
service, the local value replaces or extends the original value.
137
-
138
-
For single-value options like `image`, `command` or `mem_limit`, the new value
139
-
replaces the old value.
140
-
141
-
original service:
142
-
143
-
```yaml
144
-
services:
145
-
myservice:
146
-
# ...
147
-
command: python app.py
148
-
```
149
-
150
-
local service:
151
-
152
-
```yaml
153
-
services:
154
-
myservice:
155
-
# ...
156
-
command: python otherapp.py
157
-
```
158
-
159
-
result:
160
-
161
-
```yaml
162
-
services:
163
-
myservice:
164
-
# ...
165
-
command: python otherapp.py
166
-
```
167
-
168
-
For the multi-value options `ports`, `expose`, `external_links`, `dns`,
169
-
`dns_search`, and `tmpfs`, Compose concatenates both sets of values:
170
-
171
-
original service:
172
-
173
-
```yaml
174
-
services:
175
-
myservice:
176
-
# ...
177
-
expose:
178
-
- "3000"
179
-
```
180
-
181
-
local service:
182
-
183
-
```yaml
184
-
services:
185
-
myservice:
186
-
# ...
187
-
expose:
188
-
- "4000"
189
-
- "5000"
190
-
```
191
-
192
-
result:
193
-
194
-
```yaml
195
-
services:
196
-
myservice:
197
-
# ...
198
-
expose:
199
-
- "3000"
200
-
- "4000"
201
-
- "5000"
202
-
```
203
-
204
-
In the case of `environment`, `labels`, `volumes`, and `devices`, Compose
205
-
"merges"entries together with locally defined values taking precedence. For
206
-
`environment`and `labels`, the environment variable or label name determines
207
-
which value is used:
208
-
209
-
original service:
210
-
211
-
```yaml
212
-
services:
213
-
myservice:
214
-
# ...
215
-
environment:
216
-
- FOO=original
217
-
- BAR=original
218
-
```
219
-
220
-
local service:
221
-
222
-
```yaml
223
-
services:
224
-
myservice:
225
-
# ...
226
-
environment:
227
-
- BAR=local
228
-
- BAZ=local
229
-
```
230
-
231
-
result:
232
-
233
-
```yaml
234
-
services:
235
-
myservice:
236
-
# ...
237
-
environment:
238
-
- FOO=original
239
-
- BAR=local
240
-
- BAZ=local
241
-
```
242
-
243
-
Entries for `volumes` and `devices` are merged using the mount path in the
244
-
container:
245
-
246
-
original service:
247
-
248
-
```yaml
249
-
services:
250
-
myservice:
251
-
# ...
252
-
volumes:
253
-
- ./original:/foo
254
-
- ./original:/bar
255
-
```
256
-
257
-
local service:
258
-
259
-
```yaml
260
-
services:
261
-
myservice:
262
-
# ...
263
-
volumes:
264
-
- ./local:/bar
265
-
- ./local:/baz
266
-
```
267
-
268
-
result:
269
-
270
-
```yaml
271
-
services:
272
-
myservice:
273
-
# ...
274
-
volumes:
275
-
- ./original:/foo
276
-
- ./local:/bar
277
-
- ./local:/baz
278
-
```
279
-
280
-
For more merging rules, see [Merge and override](/reference/compose-file/merge.md) in the Compose Specification.
281
-
282
274
## Example
283
275
284
276
A common use case for multiple files is changing a development Compose app
@@ -335,7 +327,7 @@ services:
335
327
When you run `docker compose up` it reads the overrides automatically.
336
328
337
329
To use this Compose app in a production environment, another override file is created, which might be stored in a different git
0 commit comments