Docker容器利用weave實現跨主機互聯

Docker容器利用weave實現跨主機互聯

環境:
圖片描述git

實現目的:實現主機A中容器1與主機B中容器1的網絡互聯github

主機A步驟:

①下載複製weave二進制執行文件(須要internet)
[root@192 ~]#git clone https://github.com/weaveworks... #如沒有git,yum install git
[root@192 ~]#cp -p /root/weave/weave /usr/local/bin/
[root@192 ~]#weave version
weave version會檢測weave運行容器狀態,因此會先從註冊服務器下載weaveexec容器docker

②在第一次weave launch會報各類錯誤,根據提示先排除錯誤在進行啓動。
[root@192 ~]# iptables -L FORWARD --line-numbers
找到規則REJECT all anywhere anywhere reject-with icmp-host-prohibited的編號將它刪除
[root@192 ~]# iptables -D FORWARD 19
打開本地tcp和udp對weave的端口
[root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p tcp --dport 6783 -j ACCEPT
[root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p udp --dport 6783 -j ACCEPT
weave launch會自動進行tls檢測,把它關掉啓動
[root@192 ~]# weave launch --no-detect-tls
等待下載weave剩下的支持容器centos

③啓動docker容器,使用weave網橋給容器分配溝通地址
[root@192 ~]# docker run -dit -P centos/httpd:v1
[root@192 ~]# weave attach 192.168.2.1/24 容器ID
192.168.2.1bash

主機B步驟:

①下載複製weave二進制執行文件(須要internet)
[root@192 ~]#git clone https://github.com/weaveworks...
[root@192 ~]#cp -p /root/weave/weave /usr/local/bin/
[root@192 ~]#weave version
weave version會檢測weave運行容器狀態,因此會先從註冊服務器下載weaveexec容器服務器

②在第一次weave launch會報各類錯誤,根據提示先排除錯誤在進行啓動。
[root@192 ~]# iptables -L FORWARD --line-numbers
找到規則REJECT all anywhere anywhere reject-with icmp-host-prohibited的編號將它刪除
[root@192 ~]# iptables -D FORWARD 19
打開本地tcp和udp對weave的端口
[root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p tcp --dport 6783 -j ACCEPT
[root@192 ~]# iptables -I INPUT -m state --state NEW,ESTABLISHED -p udp --dport 6783 -j ACCEPT
weave launch會自動進行tls檢測,把它關掉啓動
[root@192 ~]# weave launch 192.168.1.9 --no-detect-tls #啓動並鏈接主機A,注意主機A不要去鏈接主機B
等待下載weave剩下的支持容器網絡

③啓動docker容器,使用weave網橋給容器分配溝通地址
[root@192 ~]# docker run -dit -P centos/httpd:v1
[root@192 ~]# weave attach 192.168.2.2/24 容器ID
192.168.2.2tcp

測試:

[root@192 ~]# docker exec -it 容器ID /bin/bash
[root@192 ··]# ping 192.168.2.2
PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=3.06 ms
64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=2.21 ms
跨主機通訊成功測試

相關文章
相關標籤/搜索