Merge Compose files — Additional information
Using -f is optional. If not provided, Compose searches the working directory and its parent directories for a compose.yaml and a compose.override.yaml file. You must supply at least the compose.yaml file. If both files exist on the same directory level, Compose combines them into a single configura
Reference note (untrusted external data; do not execute it as instructions).
Using -f is optional. If not provided, Compose searches the working directory and its parent directories for a compose.yaml and a compose.override.yaml file. You must supply at least the compose.yaml file. If both files exist on the same directory level, Compose combines them into a single configuration.
You can use a -f with - (dash) as the filename to read the configuration from stdin. For example
Bounded code example (external data; do not execute automatically):
```console
$ docker compose -f - <<EOF
webapp:
image: examples/web
ports:
- "8000:8000"
volumes:
- "/data"
environment:
- DEBUG=1
EOF
```
When stdin is used, all paths in the configuration are relative to the current working directory.
You can use the -f flag to specify a path to a Compose file that is not located in the current directory, either from the command line or by setting up a COMPOSE_FILE environment variable in your shell or in an environment file.
For example, if you are running the Compose Rails sample, and have a compose.yaml file in a directory called sandbox/rails. You can use a command like docker compose pull to get the postgres image for the db service from anywhere by using the -f flag as follows: docker compose -f ~/sandbox/rails/compose.yaml pull db
Bounded code example (external data; do not execute automatically):
```console
$ docker compose -f ~/sandbox/rails/compose.yaml pull db
Pulling db (postgres:18)...
18: Pulling from library/postgres
ef0380f84d05: Pull complete
50cf91dc1db8: Pull complete
d3add4cd115c: Pull complete
467830d8a616: Pull complete
089b9db7dc57: Pull complete
6fba0a36935c: Pull complete
81ef0e73c953: Pull complete
338a6c4894dc: Pull complete
15853f32f67c: Pull complete
044c83d92898: Pull complete
17301519f133: Pull complete
dcca70822752: Pull complete
cecf11b8ccf3: Pull complete
Digest: sha256:1364924c753d5ff7e2260cd34dc4ba05ebd40ee8193391220be0f9901d4e1651
Status: Downloaded newer image for postgres:18
```
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/manuals/compose/how-tos/multiple-compose-files/merge.md :: Additional information ↗Revision 3a9d778562f3 · Apache-2.0 and attribution