<p>You can use the <a href="https://docs.docker.com/compose/multiple-compose-files/extends/" rel="nofollow noreferrer"><code>extends attribute</code></a> in your docker compose file.</p>
<blockquote>
<p>Docker Compose's extends attribute lets you share common configurations among different files, or even different projects entirely.</p>
</blockquote>
<p>If you have a <code>common-services.yml</code>:</p>
<pre><code>services:
  webapp:
    build: .
    ports:
      - &quot;8000:8000&quot;
    volumes:
      - &quot;/data&quot;
</code></pre>
<p>You can then reuse <code>common-services.yml</code> in another docker compose file:</p>
<pre><code>services:
  web:
    extends:
      file: common-services.yml
      service: webapp
</code></pre>
<p>Read the <a href="https://docs.docker.com/compose/multiple-compose-files/extends/" rel="nofollow noreferrer">documentation</a> for more information.</p>

CC BY-SA 4.0
2024-08-17T08:23:01.680Z
2024-08-17T08:23:01.680Z
Ortomala Lokni
<p>Let's say I have system A started by a compose file A_compose, let's say I want to start system A from compose file B which also does other stuff.</p>
<p>Can I execute a compose file in another directory using the top level compose file?</p>

CC BY-SA 4.0
2024-07-31T15:47:56.647Z
This is exactly what compose does already. Are you talking about factorising the solution to avoid having a file get too big?
Bruce Becker
CC BY-SA 4.0
2024-07-31T16:22:25.567Z
I want to build multiple compose files
maxical
CC BY-SA 4.0
2024-08-03T03:27:15.273Z
A compose file doesn't "execute" anything other than Docker containers. You could do something janky involving granting a container spawned by the compose file access to the docker socket, and have that container run a `docker compose up`, but I think that would be a lot of work for little gain.
larsks
<docker><docker-compose>
Launching compose file from compose file
maxical
# Launching compose file from compose file

(Asked by: username_0 on 2024-07-31)

Let's say I have system A started by a compose file A\_compose, let's say I want to start system A from compose file B which also does other stuff.

Can I execute a compose file in another directory using the top level compose file?

**Tags:** docker, docker-compose

> **Comments:**
> **username_1**: This is exactly what compose does already. Are you talking about factorising the solution to avoid having a file get too big?  
> **username_0**: I want to build multiple compose files  
> **username_2**: A compose file doesn't "execute" anything other than Docker containers. You could do something janky involving granting a container spawned by the compose file access to the docker socket, and have that container run a `docker compose up`, but I think that would be a lot of work for little gain.  

---

## 1 answers

### Answer by username_3 on 2024-08-17. Score: 1

You can use the extends attribute in your docker compose file.

Docker Compose's extends attribute lets you share common configurations among different files, or even different projects entirely.

If you have a common-services.yml:
services:
  webapp:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - "/data"

You can then reuse common-services.yml in another docker compose file:
services:
  web:
    extends:
      file: common-services.yml
      service: webapp

Read the documentation for more information.


---

