docker跨主机网络通信实践

一、测试环境

consul:192.168.1.101 centos7
node1:192.168.1.102 centos7
node2:192.168.1.103 centos7

二、环境准备

    *注意node1和node2服务器的hostname,确保不相同,以防服务发现中冲突

    参照docker官方安装最新版服务,本次测试使用1.10.3,详见:https://docs.docker.com/engine/installation/linux/centos/

三、环境配置

1、consul:

    docker run -d -p "8500:8500" -h "consul" progrium/consul -server -bootstrap

2、node1:

    docker启动核心参数:

        docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-advertise 192.168.1.102:2375 --cluster-store consul://192.168.1.101:8500   

3、node2:

    docker启动核心参数:

        docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-advertise 192.168.1.103:2375 --cluster-store consul://192.168.1.101:8500

4、node1和node2防火墙配置

iptables -I INPUT -p tcp --dport 2375 -j ACCEPT
iptables -I INPUT -p tcp --dport 7946 -j ACCEPT
iptables -I INPUT -p udp --dport 7946 -j ACCEPT
iptables -I INPUT -p udp --dport 4789 -j ACCEPT

四、跨主机网络(node1和node2)

1、显示主机网络信息

    docker network ls

2、创建网络

    docker network create -d overlay net-test

    网络创建完成后,可以通过docker network ls查看,宿主机网络应该完成同步

3、创建容器

    node1:docker run -itd --name=test1 --net=net-test busybox

    node2:docker run -itd --name=test2 --net=net-test busybox

4、网络测试

    node1:docker exec test1 ping test2

    node2:docker exec test2 ping test1



转载于:https://my.oschina.net/thmz/blog/659586

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值