1. Docker跨主机容器之间的通信macvlan
默认一个物理网卡,只有一个物理mac地址,虚拟多个mac地址
1. 创建macvlan网络 【两个节点都执行】
docker network create
[root@docker01 ~]
[root@docker02 ~]
2. 两个容器相互ping,可pint通正常
/
PING 10.0.0.66 (10.0.0.66): 56 data bytes
64 bytes from 10.0.0.66: seq=0 ttl=64 time=0.631 ms
64 bytes from 10.0.0.66: seq=1 ttl=64 time=1.720 ms
^C
3. 设置eth0的网卡为混杂模式 ubuntu需要开启
ip link set eth0 promisc on
4. 创建使用macvlan网络的容器
docker run -it
2. Dcoker跨主机容器通信之overlay
http:
1.docker03安装docker consul存储ip地址的分配
启动docker服务
systemctl start docker
systemctl enable docker
导入镜像
[root@docker03 ~]
2.启动容器并设置容器的主机名
[root@docker03 ~]
3.consul:kv类型的存储数据库(key:value)
docker01、02上操作:
[root@docker01 ~]
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries": ["10.0.0.12"],
"cluster-store": "consul://10.0.0.13:8500",
"cluster-advertise": "10.0.0.11:2376"
}
systemctl restart docker
[root@docker02 ~]
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries": ["10.0.0.12"],
"cluster-store": "consul://10.0.0.13:8500",
"cluster-advertise": "10.0.0.12:2376"
}
systemctl restart docker
4. 创建overlay网络[docker01 | docker02] 全局网络
[root@docker01 ~]
5.查看集群网络信息
[root@docker01 ~]
NETWORK ID NAME DRIVER SCOPE
6c757887ba69 bridge bridge local
8501e74d4174 host host local
901eb4ba5ac2 macvlan_1 macvlan local
95dd4834641c none null local
a18966b7d57e ol1 overlay global
6.启动容器测试
[root@docker01 ~]
/
PING test02 (172.16.2.2): 56 data bytes
64 bytes from 172.16.2.2: seq=0 ttl=64 time=20.107 ms
64 bytes from 172.16.2.2: seq=1 ttl=64 time=0.469 ms
64 bytes from 172.16.2.2: seq=2 ttl=64 time=0.442 ms
^C
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.442/7.006/20.107 ms
[root@docker02 ~]
/
PING test01 (172.16.2.1): 56 data bytes
64 bytes from 172.16.2.1: seq=0 ttl=64 time=1.394 ms
64 bytes from 172.16.2.1: seq=1 ttl=64 time=0.699 ms
64 bytes from 172.16.2.1: seq=2 ttl=64 time=0.421 ms
^C
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.421/0.838/1.394 ms
7. 为什么可以ping通呢?
因为内部有一个小DNS
/
nameserver 127.0.0.11
options ndots:0
每个容器有两块网卡,eth0实现容器间的通讯,eth1实现容器访问外网(通过nat转换上的网)
每创建一个overlay网络,会自动创建一个网关
看如下架构图
8.登录 http:
结果:有两个nodes