Docker-使用weave实现跨主机容器连接

 

 

 

Weave简介

【Docker容器的跨主机访问】- 使用weave实现跨主机容器连接



 

机器1(2.9)

--------------------------------------------

直接从github下载二进制文件安装

[email protected]:~#wget -O /usr/local/bin/weavehttps://raw.githubusercontent.com/weaveworks/weave/v1.9.8/weave

[email protected]:~#chmod a+x /usr/local/bin/weave

 

启动weave路由器

[email protected]:~#weave launch

 

 

查看网桥信息

[email protected]:~#brctl show

bridge name    bridgeid           STP enabled    interfaces

docker0            8000.02421d940889       no            

weave              8000.e2cf65d8804e        no             vethwe-bridge

 

 

查看镜像

[email protected]:~#docker images

REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE

cct                   latest             9ca8d599337a        28 hoursago        239MB

weaveworks/weaveexec   latest              f8f2bacce064        4 days ago          108MB

weaveworks/weave       latest              97d546443db4        4 days ago          58.3MB

ubuntu                 latest              d355ed3537e9        12 days ago         119MB

hello-world            latest              1815c82652c0        2 weeks ago         1.84kB

weaveworks/weavedb     latest              3f610642de09        6 weeks ago         252B

[email protected]:~#

 

 

 

 

 

机器1(2.10)

--------------------------------------------

 

查看网桥信息

[email protected]:~#brctl show

bridge name    bridgeid           STP enabled    interfaces

docker0            8000.02420e860673       no            

 

 

直接从github下载二进制文件安装

[email protected]:~#wget -O /usr/local/bin/weavehttps://raw.githubusercontent.com/weaveworks/weave/v1.9.8/weave

[email protected]:~#chmod a+x /usr/local/bin/weave

 

 

#启动weave并指定机器1IP地址,以便2台机器可以连接在一起

[email protected]:~#weave launch 192.168.2.9

3344a8ec02ae0511827ad6b6619014360987632764b63737c1dff9607169c625

[email protected]:~#

 

 

再次查看网桥信息

[email protected]:~#brctl show

bridge name    bridgeid           STP enabled    interfaces

docker0            8000.02420e860673       no            

weave              8000.4a7558511801       no             vethwe-bridge

[email protected]:~#

 

 

启动一个容器并指定IP

[email protected]:~#c2=$(weave run 192.168.10.2/24 -it cct /bin/bash)

[email protected]:~#echo $c2

83bc5b4ec9b4be265376c425f3a53a47c8798a67e731660408c09acc2e79267c

[email protected]:~#docker attach $c2

[email protected]:/# ifconfig

eth0     Link encap:Ethernet  HWaddr02:42:ac:11:00:02 

         inet addr:172.17.0.2 Bcast:0.0.0.0  Mask:255.255.0.0

          UPBROADCAST RUNNING MULTICAST MTU:1500  Metric:1

          RXpackets:56 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:0 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:0

          RXbytes:9106 (9.1 KB)  TX bytes:0 (0.0 B)

 

ethwe    Link encap:Ethernet  HWaddr82:c3:c0:f1:c2:61 

         inet addr:192.168.10.2 Bcast:0.0.0.0  Mask:255.255.255.0

          UPBROADCAST RUNNING MULTICAST MTU:1376  Metric:1

          RXpackets:25 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:1 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RXbytes:3922 (3.9 KB)  TX bytes:42 (42.0 B)

 

lo       Link encap:Local Loopback 

         inet addr:127.0.0.1 Mask:255.0.0.0

          UPLOOPBACK RUNNING  MTU:65536  Metric:1

          RXpackets:0 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:0 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:0

          RXbytes:0 (0.0 B)  TX bytes:0 (0.0 B)

 

[email protected]:/#

 

 

 

 

2台机器中的容器互ping

--------------------------------------------

在机器1(2.9)上启动一个容器并指定IP

[email protected]:~#weave run 192.168.10.10/24 -it --name wc1 cct /bin/bash

5534c929688fdf5ddd833bced7b75b0fab470ed1ff09f52f3a1a66691b821322

[email protected]:~#docker attach wc1

[email protected]:/#

[email protected]:/# ifconfig

eth0     Link encap:Ethernet  HWaddr02:42:ac:11:00:02 

         inet addr:172.17.0.2 Bcast:0.0.0.0  Mask:255.255.0.0

          UPBROADCAST RUNNING MULTICAST MTU:1500  Metric:1

          RXpackets:54 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:0 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:0

          RXbytes:8812 (8.8 KB)  TX bytes:0 (0.0 B)

 

ethwe    Link encap:Ethernet  HWaddrfa:31:8d:64:76:b8 

         inet addr:192.168.10.10 Bcast:0.0.0.0  Mask:255.255.255.0

          UPBROADCAST RUNNING MULTICAST MTU:1376  Metric:1

          RXpackets:24 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:1 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:0

          RXbytes:3783 (3.7 KB)  TX bytes:42 (42.0 B)

 

lo       Link encap:Local Loopback 

         inet addr:127.0.0.1 Mask:255.0.0.0

          UPLOOPBACK RUNNING  MTU:65536  Metric:1

          RXpackets:0 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:0 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:0

          RXbytes:0 (0.0 B)  TX bytes:0 (0.0 B)

 

 

 

在机器1(2.9)中的容器ping机器2上的容器10.2

[email protected]:/#ping 192.168.10.2

64 bytes from 192.168.10.2: icmp_seq=4 ttl=64time=0.395 ms

[email protected]:/#

 

 

 

 

 

 

 

 

 

 

 

相关文章:

  • 2021-10-26
  • 2021-11-03
  • 2021-12-27
  • 2023-01-04
  • 2021-05-15
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-09
  • 2021-12-16
  • 2021-11-29
  • 2021-11-12
  • 2021-07-17
  • 2022-12-23
相关资源
相似解决方案