weave是Weaveworks開發的容器網路解決方案。weave建立的虛擬網路可以將部署在多個host上的容器連線起來。
對於容器來說,weave就像一個巨大的乙太網交換機,所有容器都被接入這個交換機,容器可以直接通訊,無需NAT和埠對映。
除此之外,weave的DNS模組使容器可以通過hostname訪問
實驗環境
weave不依賴分散式資料庫(etcd或者consul)儲存交換網路資訊。每個主機上只需執行weave元件就能建立起跨host容器網路。
# 1、下載安裝weave
root@host1:~# curl -L git.io/weave -o /usr/local/bin/weave
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
100 595 0 595 0 0 213 0 --:--:-- 0:00:02 --:--:-- 581k
100 52227 100 52227 0 0 11236 0 0:00:04 0:00:04 --:--:-- 58616
root@host1:~# chmod a+x /usr/local/bin/weave
# 2、執行weave
root@host1:~# weave launch
2.5.1: Pulling from weaveworks/weave
a073c86ecf9e: Pull complete
950f028f729b: Pull complete
d1298aa928c2: Pull complete
1d157c01c74e: Pull complete
c458f7a37ca6: Pull complete
Digest: sha256:a170dd93fa7e678cc37919ffd65601d1015da6c3f10878534ac237381ea0db19
Status: Downloaded newer image for weaveworks/weave:2.5.1
latest: Pulling from weaveworks/weavedb
9b0681f946a1: Pull complete
Digest: sha256:c280cf4e7208f4ca0d2514539e0f476dd12db70beacdc368793b7736de023d8d
Status: Downloaded newer image for weaveworks/weavedb:latest
Unable to find image 'weaveworks/weaveexec:2.5.1' locally
2.5.1: Pulling from weaveworks/weaveexec
a073c86ecf9e: Already exists
950f028f729b: Already exists
d1298aa928c2: Already exists
1d157c01c74e: Already exists
c458f7a37ca6: Already exists
49a09e96fcfc: Pull complete
6d57eb599283: Pull complete
259765bea433: Pull complete
c11f30d06b58: Pull complete
Digest: sha256:ad53aaabf648548ec26cceac3ab49394778322e1623f0d184a2b74ad06338087
Status: Downloaded newer image for weaveworks/weaveexec:2.5.1
7e8598656934a6655d16c34eeb1df238acf76692f7f5f530101ac5c722a78f43
# 3、檢視weave執行狀態,容器和網路
root@host1:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e8598656934 weaveworks/weave:2.5.1 "/home/weave/weaver …" 27 seconds ago Up 26 seconds weave
65fab63189a6 weaveworks/weaveexec:2.5.1 "data-only" 27 seconds ago Created weavevolumes-2.5.1
a4d5d7b88819 weaveworks/weavedb:latest "data-only" 28 seconds ago Created weavedb
root@host1:~# docker network ls
NETWORK ID NAME DRIVER SCOPE
59984053007a bridge bridge local
bb03f7574aa2 host host local
d60df792c936 mac_net1 macvlan local
884e50ddfb92 mac_net10 macvlan local
c402380a197d mac_net20 macvlan local
11e39328a6d1 none null local
e364db005326 weave weavemesh local
root@host1:~# docker network inspect weave
[
{
"Name": "weave",
"Id": "e364db00532678e57f983e286f31ccc10a9fdb152b7b87dafcf48e7675dff3fc",
"Created": "2019-04-03T08:35:57.945367052+08:00",
"Scope": "local",
"Driver": "weavemesh",
"EnableIPv6": false,
"IPAM": {
"Driver": "weavemesh",
"Options": null,
"Config": [
{
"Subnet": "10.32.0.0/12"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"works.weave.multicast": "true"
},
"Labels": {}
}
]