1

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?

3
  • This is exactly what compose does already. Are you talking about factorising the solution to avoid having a file get too big? Commented Jul 31 at 15:47
  • I want to build multiple compose files
    – maxical
    Commented Jul 31 at 16:22
  • 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
    Commented Aug 3 at 3:27

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.