Docker系列(五)OVS+Docker网络打通示例
来源:互联网 发布:spss信度分析 输入数据 编辑:程序博客网 时间:2024/06/08 00:33
环境说明
- 两个虚拟机
- 操作系统Centos7
- DOcker版本1.8
脚本内容:
1 # From http://goldmann.pl/blog/2014/01/21/connecting-docker-containers-on-multiple-hosts/ 2 # Edit this variable: the 'other' host. 3 REMOTE_IP=192.168.0.103 4 5 # Edit this variable: the bridge address on 'this' host. 6 BRIDGE_ADDRESS=172.17.43.1/24 7 8 # Name of the bridge (should match /etc/default/docker). 9 BRIDGE_NAME=docker0 10 11 # bridges 12 13 # Deactivate the docker0 bridge 14 ip link set $BRIDGE_NAME down 15 # Remove the docker0 bridge 16 brctl delbr $BRIDGE_NAME 17 # Delete the Open vSwitch bridge 18 ovs-vsctl del-br br0 19 # Add the docker0 bridge 20 brctl addbr $BRIDGE_NAME 21 # Set up the IP for the docker0 bridge 22 ip a add $BRIDGE_ADDRESS dev $BRIDGE_NAME 23 # Activate the bridge 24 ip link set $BRIDGE_NAME up 25 # Add the br0 Open vSwitch bridge 26 ovs-vsctl add-br br0 27 # Create the tunnel to the other host and attach it to the 28 # br0 bridge 29 ovs-vsctl add-port br0 gre0 -- set interface gre0 type=gre options:remote_ip=$REMOTE_IP 30 # Add the br0 bridge to docker0 bridge 31 brctl addif $BRIDGE_NAME br0 32 33 ip link set br0 up 34 35 # iptables rules 36 37 iptables -t nat -F;iptables -F 38 ip route add 172.17.0.0/16 dev docker0 39 # Enable NAT 40 iptables -t nat -A POSTROUTING -s 172.17.43.0/24 ! -d 172.17.43.0/24 -j MASQUERADE 41 # Accept incoming packets for existing connections 42 iptables -A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 43 # Accept all non-intercontainer outgoing packets 44 iptables -A FORWARD -i docker0 ! -o docker0 -j ACCEPT 45 # By default allow all outgoing traffic 46 iptables -A FORWARD -i docker0 -o docker0 -j ACCEPT 47 48 # Restart Docker daemon to use the new BRIDGE_NAME 49 service docker restart
说明:
在不同主机上执行以上脚本,REMOTE_IP和BRIDGE_ADDRESS根据实际地址进行调整。
结果图:
流程整理
1、关闭selinux
2、安装openvswitch并启动服务
3、添加docker0网桥,设置IP并激活该网桥
4、在ovs上添加网桥bro
5、设置该br0网桥类型及远程访问IP,实现与远程IP点对点的连接
通过ovs-vsctl add-port br0 gre0 -- set interface gre0 type=gre options:remote_ip=$REMOTE_IP命令,ovs打通了br0与指定外网IP的访问.
6、添加br0网桥到本地docker0,使容器也能够访问远程IP
0 0
- Docker系列(五)OVS+Docker网络打通示例
- Docker系列(六)路由打通网络示例
- Docker+OVS 搭建域间网络
- 五、docker的网络
- ovs+dpdk-docker实践
- 采用ovs-docker为容器创建双外部网络
- 用ovs-docker让容器网络支持Vlan隔离
- Docker系列之(五):使用Docker Compose编排容器
- Docker系列之(五):使用Docker Compose编排容器
- Docker学习系列(五):Dockerfile文件
- Docker系列~安装MySQL(五)
- 17 - Docker network第三讲-自定义网络(Docker系列)
- 18 - Docker network第四讲-网络别名(Docker系列)
- docker的五种网络模式总结
- docker网络
- Docker网络
- docker网络
- docker网络
- Webrtc服务器搭建
- Esper系列(五)Order by、Limit、构建事件流、Updating an Insert Stream
- Esper系列(六)子查询、Exists、In/not in、Any/Some、Join
- Esper系列(七)数据缓存、外部事件应用(静态方法)
- Vue.js实践<如何使用Vue2.0开发富交互式WEB应用>
- Docker系列(五)OVS+Docker网络打通示例
- 经验积累
- Esper系列(八)Method Definition、Schema
- Esper系列(九)NamedWindow语法create、Insert、select
- 第8章:TTCN-3数据类型
- Esper系列(十)NamedWindow语法delete、Select+Delete、Update
- Esper系列(十一)NamedWindow语法Merge、Queries、Indexing、Dropping
- Esper系列(十二)Variables and Constants
- GH Bladed 软件使用学习笔记(2)