---
description: How to use Docker Compose's extends keyword to share configuration between
files and projects
keywords: fig, composition, compose, docker, orchestration, documentation, docs
title: Extend your Compose file
linkTitle: Extend
weight: 20
aliases:
- /compose/extends/
- /compose/multiple-compose-files/extends/
---
Docker Compose's [`extends` attribute](/reference/compose-file/services.md#extends)
lets you share common configurations among different files, or even different
projects entirely.
Extending services is useful if you have several services that reuse a common
set of configuration options. With `extends` you can define a common set of
service options in one place and refer to it from anywhere. You can refer to
another Compose file and select a service you want to also use in your own
application, with the ability to override some attributes for your own needs.
> [!IMPORTANT]
>
> When you use multiple Compose files, you must make sure all paths in the files
are relative to the base Compose file (i.e. the Compose file in your main-project folder). This is required because extend files
need not be valid Compose files. Extend 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.
## How it works
### Extending services from another file
Take the following example:
```yaml
services:
web:
extends:
file: common-services.yml
service: webapp
```
This instructs Compose to re-use only the properties of the `webapp` service
defined in the `common-services.yml` file. The `webapp` service itself is not part of the final project.
If `common-services.yml`
looks like this:
```yaml
services:
webapp:
build: .
ports:
- "8000:8000"
volumes:
- "/data"
```
You get exactly the same result as if you wrote
`compose.yaml` with the same `build`, `ports`, and `volumes` configuration
values defined directly under `web`.
To include the service `webapp` in the final project when extending services from another file, you need to explicitly include both services in your current Compose file. For example (note this is a non-normative example):
```yaml
services:
web:
build: alpine
command: echo
extends:
file: common-services.yml
service: webapp
webapp:
extends:
file: common-services.yml
service: webapp
```
Alternatively, you can use [include](include.md).
### Extending services within the same file
If you define services in the same Compose file and extend one service from another, both the original service and the extended service will be part of your final configuration. For example:
```yaml
services:
web:
build: alpine
extends: webapp
webapp:
environment: