🎈 作者:互联网-小啊宇 🎈 简介: CSDN 运维领域创作者。目前从事 Kubernetes运维相关工作,擅长Linux系统运维、开源监控软件维护、Kubernetes容器技术、CI/CD持续集成、自动化运维、开源软件部署维护等领域。 🎈 博客首页:互联网-小啊宇
主机IP | 系统 | 服务 |
---|---|---|
192.168.1.10【docker01】 | centos7 | docker |
192.168.1.20【docker02】 | centos7 | docker |
两台服务器都操作 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
关闭沙盒
setenforce 0
vim /etc/selinux/config
#修改
SELINUX=disabled
开启路由转发
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
sysctl -p
安装docker
yum -y install docker
指定docker网段,另一台设置不同的地址段区分开
vim /usr/lib/systemd/system/docker.service
#修改
在ExecStart=后面进行添加
重新加载配置文件并启动docker
systemctl daemon-reload
systemctl restart docker
这时候可以看到有一块docker0的网卡并且IP段为指定的
测试一下,分别创建容器,互相ping
[root@docker01 ~]# docker run -itd --name Ayu1 centos:7
[root@docker02 ~]# docker run -itd --name Ayu2 centos:7
docker01主机进入容器并查看ip
[root@docker01 ~]# docker exec -it Ayu1 bash
[root@9990a5968835 /]# yum -y install net-tools #容器内默认不带一些常用命令 安装一下
[root@9990a5968835 /]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.22.2 netmask 255.255.255.0 broadcast 0.0.0.0
inet6 fe80::42:c0ff:fea8:1602 prefixlen 64 scopeid 0x20<link>
ether 02:42:c0:a8:16:02 txqueuelen 0 (Ethernet)
RX packets 8097 bytes 23203953 (22.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7877 bytes 619102 (604.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker02主机进入容器并查看ip
[root@docker02 ~]# docker exec -it Ayu2 bash
[root@602f5c97faee /]# yum -y install net-tools
[root@602f5c97faee /]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.33.2 netmask 255.255.255.0 broadcast 0.0.0.0
inet6 fe80::42:c0ff:fea8:2102 prefixlen 64 scopeid 0x20<link>
ether 02:42:c0:a8:21:02 txqueuelen 0 (Ethernet)
RX packets 8230 bytes 23212727 (22.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7961 bytes 634122 (619.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
此时可以尝试Ayu1容器 与 Ayu2容器 互相是否能ping通 Ayu1 ping Ayu2
Ayu2 ping Ayu1
docker01 主机ip{192.168.1.10} docker网段段{192.168.22.0/24}
[root@docker01 ~]# route add -net 192.168.33.0/24 gw 192.168.1.20
docker02 主机ip{192.168.1.20} docker网段段{192.168.33.0/24}
[root@docker02 ~]# route add -net 192.168.22.0/24 gw 192.168.1.10
测试容器间是否可以ping通
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有