Weave Net( https://www.weave.works )是Docker上的虛擬網絡,能夠將分佈式的Docker服務連接爲一個虛擬的服務網絡,就像在一個局域網中運行同樣,並且能夠穿透防火牆(須要開放相應端口),從而能夠構建出基於Mesh架構的對等服務網絡(https://github.com/weaveworks/mesh )。目前Weave版本是獨立發展的,還沒有歸入Docker官方體系。python
項目源碼託管在:https://github.com/weaveworks/weavegit
sudo curl -L git.io/weave -o /usr/local/bin/weave sudo chmod a+x /usr/local/bin/weave weave setup weave version weave status
weave launch weave env
weave stop
詳細說明在: https://www.weave.works/docs/net/latest/installing-weave/github
weave launch --password xxxx
在多個節點上安裝docker和weave軟件。docker
weave launch --ipalloc-range 12.32.0.0/12
注意,在阿里雲的虛擬服務器,必須使用--ipalloc-range 12.32.0.0/12
等來指定要分配的IP段,默認的已被佔用,不能使用。ubuntu
weave launch --ipalloc-range 12.32.0.0/12 192.168.1.8
其中,192.168.1.8爲剛纔創建的第一個節點(須要其餘節點都能訪問到)。這樣,一個新的節點就加入進去了。如今,運行weave status
就能夠看到有兩個節點已經造成一個虛擬網絡。瀏覽器
運行Docker容器:服務器
eval $(weave env) weave run --name amaster -it weaveworks/ubuntu
eval $(weave env) weave run --name aworker -it weaveworks/ubuntu
而後在控制檯運行ping amaster,應該能夠看到響應信息。此時,amaster和aworker已經在同一個虛擬網中,所分配的IP地址在上面所指定的12.32.0.0/12範圍內,該地址在外面是不能訪問的。網絡
weave start aworker
,若是使用docker start將致使虛擬網地址無效。Docker的其它操做相似。WeaveScope能夠對Docker運行網絡進行監控,安裝方法以下。架構
sudo curl -L git.io/scope -o /usr/local/bin/scope sudo chmod a+x /usr/local/bin/scope scope launch
而後,瀏覽器訪問:http://localhost:4040(按上面的scope啓動後提示信息)。curl
對於每個參與scope監視的節點也須要安裝scope軟件,把下面內容保存到docker-compose.yml,而後運行docker-compose up -d
便可。
version: '2' services: probe: container_name: weavescope image: weaveworks/scope network_mode: "host" restart: "always" pid: "host" privileged: true labels: - "works.weave.role=system" volumes: - "/var/run/docker.sock:/var/run/docker.sock:rw" command: - "--probe.docker" - "true"
若是對Docker基礎資源(鏡像、容器等)進行管理,建議安裝Rancher。
在RapspberryPi(樹莓派)上,使用下面方法安裝weave支持軟件。
Docker和Weave均可以支持ARM了【點擊查看最新的ARM版源碼】。
以下,能夠在樹莓派下的Raspi系統運行Weave:
sudo wget https://raw.githubusercontent.com/dilgerma/weave/rpi-latest-release/weave -O /usr/local/bin/weave #或:sudo wget git.io/rpi_weave -O /usr/local/bin/weave sudo chmod +x /usr/local/bin/weave sudo weave setup sudo weave launch #...其它操做與上面的X86同樣。
其它的板子和操做系統,可能須要進一步測試和移植。
sudo wget https://raw.githubusercontent.com/dilgerma/scope/master/scope -O /usr/local/bin/scope #或:sudo wget https://git.io/scope -O /usr/local/bin/scope chmod +x /usr/local/bin/scope scope launch
上面的只能運行在PC上,樹莓派運行報錯,發現用的是X86版本的Docker鏡像。 或者:#docker pull dilgerm/rpi-scope
,我沒試過。
而後,瀏覽器訪問:http://localhost:4040(按上面的scope啓動後提示信息)。
對於每個參與scope監視的節點也須要安裝scope軟件,把下面內容保存到docker-compose.yml,而後運行docker-compose up -d
便可。 由於樹莓派目前的Docker-Compose版本比較老,只支持docker-compose.yml的1.0格式。
probe: container_name: weavescope image: dilgerm/rpi-scope net: "host" pid: "host" restart: "always" labels: - "works.weave.role=system" volumes: - "/var/run/docker.sock:/var/run/docker.sock:rw" command: - "--probe.docker"
若是使用docker-compose.yml的2.0版本,能夠到:https://github.com/docker/compose/releases/ 下載最新的docker-compose版本,而後安裝。
wget https://github.com/docker/compose/archive/1.9.0.zip -O docker-compose.zip unzip docker-compose.zip cd docker-compose sudo pip3 install docker-py -y sudo python3 setup.py install
使用下面的文件內容保存爲docker-compose.yml:
version: '2' services: probe: container_name: weavescope image: dilgerm/rpi-scope network_mode: "host" pid: "host" restart: "always" privileged: true labels: - "works.weave.role=system" volumes: - "/var/run/docker.sock:/var/run/docker.sock:rw" command: - "--probe.docker" - "true"
weave啓動後,接管Docker的相關操做,從而創建一個新的虛擬網絡。
weave的命令行參數以下:
weave --help | help setup version
weave launch <same arguments as 'weave launch-router'> launch-router [--password <pass>] [--trusted-subnets <cidr>,...] [--host <ip_address>] [--name <mac>] [--nickname <nickname>] [--no-restart] [--resume] [--no-discovery] [--no-dns] [--ipalloc-init <mode>] [--ipalloc-range <cidr> [--ipalloc-default-subnet <cidr>]] [--log-level=debug|info|warning|error] <peer> ... launch-proxy [-H <endpoint>] [--without-dns] [--no-multicast-route] [--no-rewrite-hosts] [--no-default-ipalloc] [--no-restart] [--hostname-from-label <labelkey>] [--hostname-match <regexp>] [--hostname-replacement <replacement>] [--rewrite-inspect] [--log-level=debug|info|warning|error] launch-plugin [--no-restart] [--no-multicast-route] [--log-level=debug|info|warning|error]
weave prime
weave env [--restore] config dns-args
weave connect [--replace] [<peer> ...] forget <peer> ...
weave run [--without-dns] [--no-rewrite-hosts] [--no-multicast-route] [<addr> ...] <docker run args> ... start [<addr> ...] <container_id> attach [<addr> ...] <container_id> detach [<addr> ...] <container_id> restart <container_id>
weave expose [<addr> ...] [-h <fqdn>] hide [<addr> ...]
weave dns-add [<ip_address> ...] <container_id> [-h <fqdn>] | <ip_address> ... -h <fqdn> dns-remove [<ip_address> ...] <container_id> [-h <fqdn>] | <ip_address> ... -h <fqdn> dns-lookup <unqualified_name>
weave status [targets | connections | peers | dns | ipam] report [-f <format>] ps [<container_id> ...]
weave stop stop-router stop-proxy stop-plugin
weave reset [--force] rmpeer <peer_id> ...
where <peer> = <ip_address_or_fqdn>[:<port>] <cidr> = <ip_address>/<routing_prefix_length> <addr> = [ip:]<cidr> | net:<cidr> | net:default <endpoint> = [tcp://][<ip_address>]:<port> | [unix://]/path/to/socket <peer_id> = <nickname> | <weave internal peer ID> <mode> = consensus[=<count>] | seed=<mac>,... | observer