3

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

1 Answer 1

8

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

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

Comments

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.