--- description: How merging Compose files works keywords: compose, docker, merge, compose file title: Merge Compose files --- Docker Compose lets you merge and override a set of Compose files together to create a composite Compose file. By default, Compose reads two files, a `compose.yml` and an optional `compose.override.yml` file. By convention, the `compose.yml` contains your base configuration. The override file can contain configuration overrides for existing services or entirely new services. If a service is defined in both files, Compose merges the configurations using the rules described below and in the [Compose Specification](/reference/compose-file/merge.md). ## How to merge multiple Compose files To use multiple override files, or an override file with a different name, you can either use the pre-defined [COMPOSE_FILE](../environment-variables/envvars.md#compose_file) environment variable, or use the `-f` option to specify the list of files. Compose merges files in the order they're specified on the command line. Subsequent files may merge, override, or add to their predecessors. For example: ```console $ docker compose -f compose.yml -f compose.admin.yml run backup_db ``` The `compose.yml` file might specify a `webapp` service. ```yaml webapp: image: examples/web ports: - "8000:8000" volumes: - "/data" ``` The `compose.admin.yml` may also specify this same service: ```yaml webapp: environment: - DEBUG=1 ``` Any matching fields override the previous file. New values, add to the `webapp` service configuration: ```yaml webapp: image: examples/web ports: - "8000:8000" volumes: - "/data" environment: - DEBUG=1 - ANOTHER_VARIABLE=value ``` > [!IMPORTANT] > > 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 with `-f`). This is required because override files need not be valid Compose files. Override files can contain small fragments of configuration. Tracking which fragment of a service is relative to which path is difficult and confusing, so to keep paths easier to understand, all paths must be defined relative to the base file. ### Additional information - 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. - 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. - You can use a `-f` with `-` (dash) as the filename to read the configuration from `stdin`. For example: ```console $ docker compose -f - <