Communication between Docker containers on different networks on the same host

Any opportunity to create containers on different networks of the same host for communication? Please note that I am not using dockers at the moment.

The following is a summary of what I have done. I created two networks using the following commands

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

Then I ran two containers on each of these networks created 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

Then 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 that I was able to communicate between containers on the same network, but I could not communicate between containers on networks. Communication is possible only by adding containers to the same network.

Many thanks...

+9
3

, .

)

( , ).

b)

.

docker run --net, , , docker start , docker network connect .


, , : fooobar.com/questions/1633096/...

+4

, iptables . DOCKER-ISOLATION-STAGE-1 DOCKER-ISOLATION-STAGE-2 .

    sudo iptables -t filter -vL

DOCKER-USER, . mynetwork1 mynetwork2.

(mynetwork1 mynetwork2). br-07d0d51191df br-85f51d1cfbf6, "ifconfig" "ip link show". , , inet ( ifconfig) , 'docker network inspect mynetwork1'

    sudo iptables -I DOCKER-USER -i br-########1 -o br-########2 -j ACCEPT
    sudo iptables -I DOCKER-USER -i br-########2 -o br-########1 -j ACCEPT

, IP-. ,

    sudo iptables -I DOCKER-USER -i br-########1 -o br-########2 -s 172.17.0.2 -d 172.19.0.2 -j ACCEPT
    sudo iptables -I DOCKER-USER -i br-########2 -o br-########1 -s 172.19.0.2 -d 172.17.0.2 -j ACCEPT
+4

According to Docker Docs, Containers can only communicate within networks but not across networksyou can connect a container to two networks and have the ability to exchange data.

edit: Although at this point, why do we need two networks.

Here is the link:

https://docs.docker.com/engine/userguide/networking/dockernetworks/

Bruce

0
source

All Articles