Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose link container of another docker-compose

I'm a bit confused on how to setup my environment with docker-compose. I want to have the following:

  • docker-compose file for an ELK stack
  • docker-compose file for web application A with filebeat
  • docker-compose file for web application B with filebeat

I want to stop/start/build the ELK stack container independently from the containers of the web applications A/B. But i would like to link the containers to the ELK stack container to open the connection for filebeat.

What I'm looking for would be like this:

  1. No container is running
  2. docker-compose up in the web app A folder. No elk container is running. Starts ELK stack and then web app A container.
  3. docker-compose up in the web app B folder. Elk container is already running (from 1). Does not start an additional ELK stack. Starts web app B.
  4. docker-compose stop in elk stack container works
  5. docker-compose start in elk stack container works and "reconnects".

Is this somehow possible. I did not get it to work with extends or link.

Thanks in advance

like image 549
user984200 Avatar asked Mar 08 '26 21:03

user984200


1 Answers

Docker networking is the key here. You can do:

$ docker network create some-net

Then in your compose files, add the following to the bottom:

networks:
  default:
    external:
      name: some-net

This will set the default network (for each container) to be a previously defined network (some-net). All containers (regardless of the compose file they were defined in) should then be able to communicate with each other using the built-in service name DNS resolution.

Relevant docs: https://docs.docker.com/compose/networking/#/using-a-pre-existing-network

like image 192
johnharris85 Avatar answered Mar 11 '26 11:03

johnharris85



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!