db 是容器的别名,同时也可以用 容器名 mysql,或用 mysql 容器的ip
3306 是容器的端口号,不是对外暴露的端口切记
--net 网络互连bridge网桥模式
创建一个bridge网络命名docker-mount_default
docker network create -d bridge docker-mount_default
[root@ecs-149911 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
f297f786d4b5 bridge bridge local
c3509a01b631 docker-mount_default bridge local
f7f0029f747b host host local
454e6fbe8a40 none null local
docker exec -it miliqk-manage-platform bash
root@28443415a16f:/# ping mysql02
PING mysql (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: icmp_seq=0 ttl=64 time=0.065 ms
64 bytes from 172.18.0.3: icmp_seq=1 ttl=64 time=0.084 ms
64 bytes from 172.18.0.3: icmp_seq=2 ttl=64 time=0.082 ms
64 bytes from 172.18.0.3: icmp_seq=3 ttl=64 time=0.097 ms
进入到mysql02容器 ping miliqk-manage-platform 查看效果
[root@ecs-149911 ~]# docker exec -it mysql02 bash
root@ecf2f7975ad8:/# ping miliqk-manage-platform
PING miliqk-manage-platform (172.18.0.5) 56(84) bytes of data.
64 bytes from miliqk-manage-platform.docker-mount_default (172.18.0.5): icmp_seq=1 ttl=64 time=0.077 ms
64 bytes from miliqk-manage-platform.docker-mount_default (172.18.0.5): icmp_seq=2 ttl=64 time=0.058 ms
64 bytes from miliqk-manage-platform.docker-mount_default (172.18.0.5): icmp_seq=3 ttl=64 time=0.057 ms