Communication between containers in different networks

Hi there…

I want my containers in different networks to communicate with each other.
So I created two networks using

docker network create --driver bridge mynetwork1 docker network create --driver bridge mynetwork2

Then I ran two containers on each of these created networks using the commands:

docker run --net=mynetwork1 -it name=mynet1container1 mycontainerimage docker run --net=mynetwork1 -it name=mynet1container2 mycontainerimage docker run --net=mynetwork2 -it name=mynet2container1 mycontainerimage docker run --net=mynetwork2 -it name=mynet2container2 mycontainerimage

I identified the IP Addresses of each of the containers from the networks created using

docker network inspect mynetwork1 docker network inspect mynetwork2

Using those I was able to communicate between the containers in the same network, but I could not communicate between the containers across the networks. Communication was possible only by adding the containers to the same network.

Any possibility to make containers in different networks to communicate?

Much thanks…

I think the idea (at least today) is that if you want two containers to be able to communicate, you should put them on the same network.

Why do you want containers on different networks to be able to communicate? One container can actually belong to multiple networks, so if you wanted containers A, B, and C where A <=> B and B <=> C but A and C cannot communicate, you could do so (Either using Compose’s networks key for services or by executing extra docker network connect commands after docker run).

Hey I read everywhere that to comunicate 2 containers have to be in the same network, and it give me a problem.
I have a docker on a server and I want to make it comunicate with an other server where are some apis in container or out so my question is is it possible to make them comunicate ?
In a practical way I have kong inside a container and I want to add api from other servers so is it possible in the case of non-dockerized api and in the case of dokerized one ?
My issue is if 2 container have to be part of the same docker network to comunicate how can I make containers on different physical server to comunicate