Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2024-08-17T08:23:01.680Z
Answers: 2024-08-17T08:23:01.680Z
Answers: Ortomala Lokni
Body: <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>
  
Comments: CC BY-SA 4.0
Comments: 2024-07-31T15:47:56.647Z
Comments: This is exactly what compose does already. Are you talking about factorising the solution to avoid having a file get too big?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2024-07-31T16:22:25.567Z
Comments: I want to build multiple compose files
Comments: maxical
Comments: CC BY-SA 4.0
Comments: 2024-08-03T03:27:15.273Z
Comments: 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.
Comments: larsks
Tags: <docker><docker-compose>
Title: Launching compose file from compose file
UserDisplayName: maxical
ThreadText: # 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`](https://docs.docker.com/compose/multiple-compose-files/extends/) 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](https://docs.docker.com/compose/multiple-compose-files/extends/) for more information.
  
  
  ---
  
  