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
• 16,710 points
3,151 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
• 42,510 points

selected May 7 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
• 6,880 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 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 by Arohi

Related Questions In Docker

+1 vote
3 answers

How do I execute multiple commands using docker-compose

You can also use the depends_on option ...READ MORE

answered Apr 22 in Docker by Kavya
14,880 views
0 votes
1 answer
+1 vote
5 answers

Set containers timezones by using docker compose.

version "2" services: serviceA: ...READ MORE

answered Jul 8, 2018 in Docker by Atul
• 10,240 points
3,246 views
0 votes
1 answer
0 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
• 56,940 points
232 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
• 42,510 points
1,029 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
• 42,510 points
644 views