Communication between multiple docker-compose projects

+1 vote

I have two separate docker-compose.yml files in two different folders:

  • ~/fp/docker-compose.yml
  • ~/ap/docker-compose.yml

How can I make sure that a container in fp can send requests to a container in ap?

Jul 30, 2018 in Docker by Hannah
• 18,520 points
14,548 views

4 answers to this question.

+1 vote
Best answer

You just need to make sure that the containers you want to talk to each other are on the same network. Networks are a first-class docker construct, and not specific to compose.

# fp/docker-compose.yml
version: '2'
services:
  front:
    ...
    networks:
      - some-net
networks:
  some-net:
    driver: bridge
...
# ap/docker-compose.yml
version: '2'
services:
  api:
    ...
    networks:
      - front_some-net
networks:
  front_some-net:
    external: true

They can then talk to each other using the service name. From frontyou can do ping api and vice versa.

answered Jul 30, 2018 by Kalgi
• 52,350 points

selected May 7, 2019 by Vardhan
+1 vote

Small addition to @kalgi's answer..

While running a docker compose file, a default network is created which can be added to the with other network file as an external network.

# fp/docker-compose.yml
version: '2'
  services:  
    front_service:
    ...

...

# ap/docker-compose.yml
version: '2'
services:
  api_service:
    ...
    networks:
      - front_default
networks:
  front_default:
    external: true
answered Aug 6, 2018 by Nilesh
• 7,060 points
0 votes

This worked for me:

version: "3.5"
services:
  proxy:
    image: user/image:tag
    ports:
      - "80:80"
    networks:
      - proxynet

networks:
  proxynet:
    name: custom_network
answered May 6, 2019 by Tim
0 votes

Another approach is to compose both the containers to the same network by composing them at the same time. Something like this:

docker compose --file ~/front/docker-compose.yml --file ~/api/docker-compose.yml up -d
answered May 6, 2019 by Arohi

Related Questions In Docker

+3 votes
4 answers

How do I execute multiple commands using docker-compose

It can be solve by using bash -c ...READ MORE

answered Sep 20, 2018 in Docker by shubham
• 7,340 points
110,945 views
0 votes
1 answer
0 votes
0 answers
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,738 views
0 votes
1 answer

Interactive shell using Docker Compose

You need to include the following lines ...READ MORE

answered Jul 26, 2018 in Docker by Kalgi
• 52,350 points
6,410 views
0 votes
1 answer

How to get docker-compose to always re-create containers from fresh images?

The containers are getting recreated to preserve ...READ MORE

answered Jul 27, 2018 in Docker by Kalgi
• 52,350 points
4,720 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP