13

I have looked at the docker docs for the answer to this question and I dont see it being laid out simply anywhere. I want to start my app in a docker using docker-compose.yml I want that docker-compose.yml to start up other containers defined in another docker-compose.yml file in a different project.

version: '3.4'

#we need network if we want the services to talk to each other
networks:
  services:
    driver: bridge

services:

  jc:
    build:
      context: .
      dockerfile: ./Dockerfile
      args:
      - PORT=8080
      network: host
    networks:
    - services
    image: jc
    container_name: jc
    ports:
    - 8080:8080

How can I edit this file so that I can run another docker-compose.yml file in a different file path when I run this docker-compose.yml file?

3
  • 2
    You can get an answer here. stackoverflow.com/questions/55650342/… You can extend the file and achieve this Commented Nov 26, 2019 at 8:05
  • @SriniM I am getting an error Unsupported config option for services.jc: 'extends'... Ive googled after this error and seems like it is not supported. Do you know anything about this? I am using docker-compose 1.24,1 Thanks. Commented Nov 26, 2019 at 19:59
  • Did you try "Use docker-compose config to generate a configuration with all extends options resolved, and deploy from that" . There are chances your compose version is not supporting extends. but i found that you can generate the compose file with all your extend configuration using docker-compose config. Try and let us know Commented Nov 27, 2019 at 5:53

2 Answers 2

17

After trying the to use the extends option of the docker-compose file and differing variations of its usage I consistently received an error indicating that extends is not supported even after updating to the latest docker version. I did however solve the problem by running this command.

docker-compose -f /path/to/other/docker-compose-file/docker-compose.yml up

I was sure that I had to add something to the docker-compose file so I overlooked this in the docs. But you can read more about it here. docker-compose docs

Sign up to request clarification or add additional context in comments.

Comments

1

This is kind of a hack but you can add another container that starts docker compose with another docker-compose file. for example:

Docker file for the starter container:

FROM ubuntu:bionic
RUN mkdir -p /compose
WORKDIR /compose
CMD ["docker-compose", "up", "-d"]

The main docker compose file (starts a redis server and the starter container). note the compose binary, docker socket and another docker-compose.yml file are mounted into the starter container:

version: '2.1'

services:

  from-main-compose:
    image: redis:3

  starter:
    image: starter:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /usr/local/bin/docker-compose:/usr/local/bin/docker-compose:ro
      - /home/shay/source/composeFromContainer/another-compose/docker-compose.yml:/compose/docker-compose.yml:ro

Second docker compose file:

version: '2.1'

services:
  redis-from-container:
    image: redis:3

The result is this:

b1faa975df49        redis:3             "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        6379/tcp            compose_redis-from-container_1
7edca79d3d99        redis:3             "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        6379/tcp            composefromcontainer_from-main-compose_1

Note that if using this hack as it is the services will be placed on different networks so this might need to be tweaked a bit.

6 Comments

Nice option as a hack. But With docker you can extend compose files. Please have a look at stackoverflow.com/questions/55650342/…
You are right. extending the compose file is a better option. thanks.
Thanks for the response. I also prefer a non hack solution. I get an error Unsupported config option for services.jc: 'extends' ... I've also read that extends is not supported. Is this true? I am using docker-compose 1.24,1
@Dan Did you try "Use docker-compose config to generate a configuration with all extends options resolved, and deploy from that" . There are chances your compose version is not supporting extends. but i found that you can generate the compose file with all your extend configuration using docker-compose config. Try and let us know
Hi @SriniM if I do the docker-compose config with the extends attribute in the file I get the same error. If I do it without that attribute then I just get an output that resembles my docker-compose file. I tried putting that output in the docker-compose file and trying to build, and compose-up but I get the same error. Should I change my docker-compose version? I believe that my current version 1.24.1 should support this feature. Any thoughts?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.