Reuse a Compose service with the extends attribute
Answer: The extends attribute lets one service reuse another service's configuration, from the same file or from another Compose file. You can override some attributes in the extending service.
Required keys and imports
The extends value must be a mapping with a required service key and an optional file key. If file is omitted, the base service is in the same Compose file. A relative file path is relative to the main Compose file. Compose does not automatically import volumes, networks, or other resources that the base service depends on. The author must declare those resources in the model that uses extends. Circular extends references are not supported.
Path rules and stack deploy
Docker's how-to says every path should be relative to the base Compose file in the main project folder, because extend files can be small fragments. extends is not supported when deploying with docker stack deploy. docker stack config on a file that uses extends reports forbidden properties.
| extends | compose | |---|---| | service | Name of the base service to reuse | | file | Optional Compose file that holds that service | | omitted file | The base service is in the same Compose file | | stack deploy | Not supported for extends |
See also
Claims
- id: C1 claim: extends lets you share common service configuration across files or projects. source: S1 evidence: "lets you share common configurations among different files"
- id: C2 claim: The extends mapping requires a service key and may include a file key. source: S1 evidence: "a required 'service' and an optional 'file' key"
- id: C3 claim: extends is not supported with docker stack deploy. source: S2 evidence: "extends is not supported when deploying with docker stack deploy"
Sources
- [S1] Compose Specification. Compose Specification. https://raw.githubusercontent.com/compose-spec/compose-spec/master/spec.md . License: Apache-2.0. Accessed 2026-11-19.
- [S2] Extend your Compose file. Docker docs. https://docs.docker.com/compose/how-tos/multiple-compose-files/extends/ . License: Apache-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Compose Specification, Compose Specification; Docker docs, Extend your Compose file. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Compose Specification, Compose Specification; Docker docs, Extend your Compose file. Apache-2.0; Apache-2.0.
Cite this
iinventedlight. 2026. "Reuse a Compose service with the extends attribute." iinventedlight Library, iil:note:9hdcjmgv, version of 2026-11-19. https://iinventedlight.com/library/notes/docker-compose-extends/. License: CC-BY-4.0.
@misc{iil_note_9hdcjmgv,
author = {{iinventedlight}},
title = {{Reuse a Compose service with the extends attribute}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/docker-compose-extends/},
note = {Permanent ID iil:note:9hdcjmgv. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- docker-compose-extends.table.json (table; CC-BY-4.0)
- docker-compose-extends.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-compose-extends.md.