If Docker technology is to be used on a large scale in production and test environments , it is first necessary to solve the problem of interconnection of Docker containers built by different physical machines . This article describes the configuration of the Docker container interconnect on different physical servers using open vswitch in the centos7 environment .
Environment Introduction:
Server1:192.168.115.5/24
Server2:192.168.115.6/24
One: install Docker on Server1 and Server2 and start the service separately in rpm mode
# Yum list *docker*# yum-y install docker# service Docker startredirecting to/bin/systemctl start Docker.service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/D9/wKiom1S-I_Hh2bgsAAGXa1qq8Rw744.jpg "title=" Picture 1.png "alt=" Wkiom1s-i_hh2bgsaagxa1qq8rw744.jpg "/>
Two : Install open vswitch on Server1 and Server2 respectively
# yum -y install wget openssl-devel kernel-devel# yum groupinstall "Development tools" # adduser ovswitch# su - ovswitch$ wget http ://openvswitch.org/releases/openvswitch-2.3.0.tar.gz$ tar -zxvpf openvswitch-2.3.0.tar.gz $ mkdir -p ~/rpmbuild/sources$ sed ' s/openvswitch-kmod, //g ' openvswitch-2.3.0/rhel/openvswitch.spec > openvswitch-2.3.0/rhel/openvswitch_no_kmod.spec$ cp openvswitch-2.3.0.tar.gz rpmbuild/sources/ $ rpmbuild -bb --without check ~/openvswitch-2.3.0/rhel/openvswitch_no_kmod.spec $ exit # yum Localinstall /home/ovswitch/rpmbuild/rpms/x86_64/openvswitch-2.3.0-1.x86_64.rpm # mkdir /etc/openvswitch# setenforce 0 # systemctl start openvswitch.service# systemctl status openvswitch.sErvice -l
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/D6/wKioL1S-JPCgVO1JAA_49emGvvo761.jpg "title=" Picture 2.png "alt=" Wkiol1s-jpcgvo1jaa_49emgvvo761.jpg "/>
Three: in the Server1 and the Server2 build OVS Bridge on the and Configure Routing
server1: docker container intranet ip Span style= "font-family: ' The song Body '; > NET segment 172.17.1.0/24
# cat /proc/sys/net/ipv4/ip_forward 1# ovs-vsctl add-br obr0# ovs-vsctl add-port obr0 gre0 -- set Interface gre0 type=gre options:remote_ip=192.168.115.5 # brctl addbr kbr0 # brctl addif kbr0 obr0 # ip link set dev docker0 down # ip link del dev docker0 # vi /etc/sysconfig/network-scripts/ Ifcfg-kbr0onboot=yesbootproto=staticipaddr=172.17.1.1netmask=255.255.255.0gateway=172.17.1.0userctl=notype= Bridgeipv6init=no # cat /etc/sysconfig/network-scripts/route-ens32 172.17.2.0/24 via 192.168.115.6 dev ens32# systemctl restart network.service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/D9/wKiom1S-JGLztcVOAAkVfvfiakg521.jpg "title=" Picture 3.png "alt=" wkiom1s-jglztcvoaakvfvfiakg521.jpg "/>650) this.width=650; src=" http://s3.51cto.com/wyfs02/M02/ 58/d6/wkiol1s-jukhpm98aamptzyexda526.jpg "title=" image 4.png "alt=" Wkiol1s-jukhpm98aamptzyexda526.jpg "/>
Server2:docker Container Intranet IP network segment 172.17.2.0/24
# cat /proc/sys/net/ipv4/ip_forward 1# ovs-vsctl add-br obr0# ovs-vsctl add-port obr0 gre0 -- set Interface gre0 type=gre options:remote_ip=192.168.115.6 # brctl addbr kbr0 # brctl addif kbr0 obr0 # ip link set dev docker0 down # ip link del dev docker0 # vi /etc/sysconfig/network-scripts/ Ifcfg-kbr0onboot=yesbootproto=staticipaddr=172.17.2.1netmask=255.255.255.0gateway=172.17.2.0userctl=notype= Bridgeipv6init=no # cat /etc/sysconfig/network-scripts/route-ens32 172.17.1.0/24 via 192.168.115.5 dev ens32 # systemctl restart network.service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/D9/wKiom1S-JJ3DpEGhAAk8rJcGxhs651.jpg "title=" Picture 5.png "alt=" wkiom1s-jj3dpeghaak8rjcgxhs651.jpg "/>650) this.width=650; src=" Http://s3.51cto.com/wyfs02/M00/ 58/d6/wkiol1s-jysi2ut_aam9jnqom84252.jpg "title=" image 6.png "alt=" Wkiol1s-jysi2ut_aam9jnqom84252.jpg "/>
Four : start the container test
Server1 and Server2 Modify Docker-initiated virtual NIC bindings to Kbr0, restart Docker process
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/D9/wKiom1S-JMvzlMcuAAGyypVRvSs783.jpg "title=" Picture 7.png "alt=" Wkiom1s-jmvzlmcuaagyypvrvss783.jpg "/>
Server1:
# docker Run-idt--name test1 Registry.fjhb.cn/centos6/bin/bash
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/D6/wKioL1S-JbCSshcMAAYrxbYbJzU457.jpg "title=" Picture 8.png "alt=" Wkiol1s-jbcsshcmaayrxbybjzu457.jpg "/>
Server2:
# docker Run-idt--name test2 Registry.fjhb.cn/centos6/bin/bash
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/D9/wKiom1S-JRujzHceAAffwv6cFsU079.jpg "title=" Picture 10.png "alt=" Wkiom1s-jrujzhceaaffwv6cfsu079.jpg "/>
Server1:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/D6/wKioL1S-JgKi_26TAALMRW9LYKQ999.jpg "title=" Picture 9.png "alt=" Wkiol1s-jgki_26taalmrw9lykq999.jpg "/>
This article from "Chop Month" blog, declined reprint!
Configuring the container interconnect between multiple Docker hosts