docker跨主机容器通信

Docker:网络模式详解

路由器地址192.168.1.1route -n查看
parent=enp7s0的以太网名用ifcofig查找

 apt install net-tools iputils-ping -y
docker network create --driver=macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=enp7s0 pub_net
$ docker run -itd --name test_pub2 --restart always --hostname test_pub2 --net pub_net tqc/hadoop:3.0
$ docker run -itd --name test_pub1 --restart always --hostname test_pub1 --net pub_net tqc/hadoop:3.0
$ docker run -itd --name test_pub3 --restart always --hostname test_pub3 --net pub_net tqc/hadoop:3.0

实验中,
在容器中ping其他容器hostname可以ping到
容器外不行
容器外其他主机是可以用ip访问容器的
容器中也可以用ip访问容器外的其他主机

发布了281 篇原创文章 · 获赞 35 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/TQCAI666/article/details/103890930