Docker 跨主机容器之间的通信macvlan

默认一个物理网卡,只有一个物理mac地址,虚拟多个mac地址

缺点:每次需要手动配置ip地址,容易ip地址冲突。类似于保存到execl表格里面。

两台物理机: docker-01和docker-02

创建macvlan网络

bash 复制代码
[root@docker-01 ~]# docker network create --driver macvlan --subnet 10.0.0.0/24 --gateway 10.0.0.254 -o parent=eth0 macvlan_1 
a2e790b4ac802c659e216b23096bb2f761361828f41498bf28392e8261fb7ea2
[root@docker-02 ~]# docker network create --driver macvlan --subnet 10.0.0.0/24 --gateway 10.0.0.254 -o parent=eth0 macvlan_1 
9c7839f953ba6f619d195872bc2a34791efa12b37c96754063041eadd876654e

创建使用macvlan网络的容器

bash 复制代码
[root@docker-01 ~]# docker run -itd --network macvlan_1 --ip=10.0.0.201 centos6_9_ssh_nginx:v1
[root@docker-02 ~]# docker run -itd --network macvlan_1 --ip=10.0.0.202 centos6_9_ssh_nginx:v1

互ping测试

bash 复制代码
[root@docker-01 ~]# docker exec -it lucid_mestorf /bin/bash
[root@cbeaf45ad4da /]# ifconfig |grep 10.0.0.
          inet addr:10.0.0.201  Bcast:10.0.0.255  Mask:255.255.255.0
[root@docker-02 ~]# docker exec -it 1e14992e9209 /bin/bash
[root@1e14992e9209 /]# ifconfig |grep 10.0.0.2
          inet addr:10.0.0.202  Bcast:10.0.0.255  Mask:255.255.255.0

在docker01的容器ping docker02容器的ip地址

在docker02的容器ping docker01容器的ip地址

bash 复制代码
[root@cbeaf45ad4da /]# ping 10.0.0.202 -c4
PING 10.0.0.202 (10.0.0.202) 56(84) bytes of data.
64 bytes from 10.0.0.202: icmp_seq=1 ttl=64 time=0.289 ms
64 bytes from 10.0.0.202: icmp_seq=2 ttl=64 time=1.44 ms
64 bytes from 10.0.0.202: icmp_seq=3 ttl=64 time=1.52 ms
64 bytes from 10.0.0.202: icmp_seq=4 ttl=64 time=1.31 ms

[root@1e14992e9209 /]# ping 10.0.0.201 -c4
PING 10.0.0.201 (10.0.0.201) 56(84) bytes of data.
64 bytes from 10.0.0.201: icmp_seq=1 ttl=64 time=2.64 ms
64 bytes from 10.0.0.201: icmp_seq=2 ttl=64 time=1.40 ms
64 bytes from 10.0.0.201: icmp_seq=3 ttl=64 time=0.521 ms
64 bytes from 10.0.0.201: icmp_seq=4 ttl=64 time=0.601 ms

设置eth0的网卡为混杂模式,ubuntu需要设置

bash 复制代码
ip link set eth1 promisc on
相关推荐
袁泽斌的学习记录7 分钟前
ubuntu22.04安装cuda11.4版本
linux·运维·服务器
荣光波比10 分钟前
Docker(一)—— Docker入门到精通:从基础概念到容器管理
运维·docker·容器·云计算
JanelSirry11 分钟前
VMware+RockyLinux+ikuai+docker+cri-docker+k8s+calico BGP网络 自用 实践笔记(二)
笔记·docker·kubernetes
m0_4646082611 分钟前
Docker入门
运维·docker·容器
JanelSirry15 分钟前
VMware+RockyLinux+ikuai+docker+cri-docker+k8s+calico BGP网络 自用 实践笔记(底稿)
网络·docker·kubernetes
游戏开发爱好者835 分钟前
Nginx HTTPS 深入实战 配置、性能与排查全流程(Nginx https
运维·nginx·ios·小程序·https·uni-app·iphone
小闫BI设源码40 分钟前
Docker的介绍
运维·docker·容器·数据持久化·端口映射·卷挂载·配置外挂
万事可爱^1 小时前
如何在云服务器上使用LLaMA Factory框架微调模型
运维·服务器·llm·sft·llama·模型微调·ai agent
霖.241 小时前
service的两种代理实现
linux·服务器·容器·kubernetes
新手小白*1 小时前
Nginx反向代理与缓存功能-第一章
运维·nginx