如何让docker上2个不同网络的容器互连(重要)
#1.使用局域名bridge
docker run --name centos1 -itd centos:latest
docker network inspect bridge
#2.使用局域网mynet
docker run --name centos2 -itd --net mynet --ip 192.168.0.12 centos:latest
docker network inspect mynet
#3.测试centos1和centos2的连接
docker exec -it centos1 ping centos2
#连接失败,控制台出现如下提示
ping: centos2: Name or service not known
#4.如何解决此问题呢?向网络mynet中添加容器centos1
docker network connect mynet centos1
为什么成功了呢?原因:容器centos1具有两个ip
#查看网络信息
docker network inspect mynet
#查看容器详细信息
docker inspect centos1