默认NAT模式
带-p端口映射可访问
-------------------------------------------------macvlan模式-------------------------------------------------
docker network create --driver macvlan --subnet=10.0.2.0/24 --gateway 10.0.2.254 -o parent=ens33 macvlan_1 (双方创建,配置模式/网段范围/网关/网卡口/名称)
[root@test1 ~]# docker network ls (查看模式)
NETWORK ID NAME DRIVER SCOPE
51b4706a686d bridge bridge local
b8ff00909e7b harbor_harbor bridge local
186bcbcbe1d7 host host local
a13a43380d11 macvlan_1 macvlan local
7f1784c7087f none null local
ip link set ens33 promisc on(所有用到的主机)
docker run --rm --network macvlan_1 -it --ip 10.0.2.1sshd:v1 /bin/bash (pc1)
docker run --rm --network macvlan_1 -it --ip 10.0.2.2 sshd:v1 /bin/bash (pc2)
进去ping即可通/退出不通方为可用
docker network ls
docker network rm [ID] 网桥关闭
-------------------------------------------------overlay模式-------------------------------------------------
docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap (用的consul镜像:后台/端口/主机名/容器名/镜像/服务?/服务?)
ip link set ens33 promisc on(所有用到的主机)
添加/etc/docker/daemon.json 三行
"hosts":["tcp://0.0.0.0:2376","unix://var/run/docker.sock"],
"cluster-store":"consul://192.168.3.228:8500",
"cluster-advertise":"192.168.3.228:2376"
如果报错情况下上述红色字不做
/usr/lib/systemd/system/docker.service中增加--cluster-store=consul://192.168.3.228:8500 --cluster-advertise=ens33:2376
改后:ExecStart=/usr/bin/dockerd --cluster-store=consul://192.168.3.228:8500 --cluster-advertise=ens33:2376 -H fd:// --containerd=/run/containerd/containerd.sock
systemctl daemon-reload && systemctl restart docker
master中创建网桥
docker network create -d overlay --subnet 172.18.0.0/24 --gateway 172.18.0.254 ol1
[root@test1/2 ~]# docker network ls 双方均可看到网桥名称
NETWORK ID NAME DRIVER SCOPE
c0b12643e4a5 bridge bridge local
c1f3f79c8451 harbor_harbor bridge local
fb19512dd895 host host local
b3324e34bfc1 none null local
733ab0de0399 ol1 overlay global
docker run -it --network ol1 --rm sshd:v1 /bin/bash (双方获取ip不一样,可ping通网关,双方互ping未解决)