Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: how to connect two bridges

As you know after Docker 1.9 we can create bridges to connect containers.

I have created two custom bridges: bridge A 172.18.0.1 and bridge B 172.19.0.1.

Now I have a container1 on bridge A, and a container2 on bridge B called "mailServer".

The container1 needs to reach container2 by a DNS, how should I do this? Because they are on different bridges so they cannot talk to each other. Do I need a router and can I achieve this by Docker?

This is a new feature of Docker and I didn't find much information. Thanks.

like image 474
hawarden_ Avatar asked Apr 11 '16 09:04

hawarden_


2 Answers

To connect container2 to container1 you can also connect it to bridgeB

$ docker network connect bridgeB container1

This will allow container1 to connect to container2 by IP address, DNS names would still have to be updated manually afaik.

More information in the Docker networking guide here.

like image 114
arunkumar Avatar answered Sep 21 '22 00:09

arunkumar


You can try making use of the veth peer so that you can connect two bridges. Make sure you are rename and names respectively with the one you configured.

ip link add veth0 type veth peer name veth1
ifconfig veth0 up
ifconfig veth1 up
brctl addif <D1-A-Bridge> veth0
brctl addif <D2-A-Bridge> veth1
like image 45
Viswesn Avatar answered Sep 23 '22 00:09

Viswesn