路由器地址192.168.1.1
用route -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访问容器外的其他主机