Nanab4u
Nanab4u

Reputation: 85

Docker bidirectional communication between containers

I'm looking out to setup bidirectional communication between docker containers.I have following containers:

1.Apache
2.Tomcat A
3.Tomcat B
4.Tomcat C
5.MySQL  

Apache acts as a reverse proxy and forwards requests to Tomcat A,B and C.All Tomcat containers will communicate with MySQL database.As of now I have links in Apache to send requests to tomcat containers and tomcat containers have links to communicate with MySQL database. Now I need to establish bidirectional communication between tomcat containers Like Tomcat A wants to talk with Tomcat B and Tomcat C and vice versa.How we can achieve this with Docker Compose ? Is it possible to provide bidirectional links in docker-compose.yml file ?

Thanks in advance.

Upvotes: 0

Views: 647

Answers (1)

michael_bitard
michael_bitard

Reputation: 4262

No, Links are not bidirectional so you can't achieve it with that.

What you can do is to set your containers in the same network, so they can access each other via their container name.

For example

docker network create newnetwork
docker run -d --name apache --net=newnetwork Apache
docker run -d --name tomcatA --net=newnetwork TomcatA
...

Doing that, the container apache will be able to ping/access tomcatA, and tomcatA will be able to ping/access apache.

Have a look at how to integrate networks with docker-compose: https://docs.docker.com/compose/networking/#specifying-custom-networks

I'm not sure of this part, but since docker ~1.10, it seems that you do not need to create a network, the default network connects all the containers together so you can already ping/access each containers from the others via their name. (look at the /etc/hosts file in the containers, if you see the other containers name and their IP you're good to go)

Upvotes: 1

Related Questions