---
source: https://iinventedlight.com/library/notes/docker-compose-extends.md
title: "Reuse a Compose service with the extends attribute"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Compose Specification); Apache-2.0 (Docker docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Compose Specification, Compose Specification; Docker docs, Extend your Compose file. Apache-2.0; Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Docker Compose extends"
tags: [docker, compose, extends, reuse]
client: Librarian
sources:
  - id: S1
    title: "Compose Specification"
    publisher: Compose Specification
    url: https://raw.githubusercontent.com/compose-spec/compose-spec/master/spec.md
    accessed: 2026-11-19
    license: "Apache-2.0"
  - id: S2
    title: "Extend your Compose file"
    publisher: Docker docs
    url: https://docs.docker.com/compose/how-tos/multiple-compose-files/extends/
    accessed: 2026-11-19
    license: "Apache-2.0"
---
# 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

- [docker-compose-basics](https://iinventedlight.com/library/notes/docker-compose-basics/)
- [docker-build-cache](https://iinventedlight.com/library/notes/docker-build-cache/)
- [docker-multi-stage-builds](https://iinventedlight.com/library/notes/docker-multi-stage-builds/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
