[root@zmr-service ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4bc7425371cb lizheming/waline:1.30.4 "docker-entrypoint.s…" 22 hours ago Up 22 hours 8360/tcp waline af3b2f1b7892 nginx:1.24.0 "/docker-entrypoint.…" 39 hours ago Up 24 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginx 60ba55559d39 snowdreamtech/frpc:0.48.0 "/bin/sh -c '/usr/bi…" 13 days ago Up 24 hours frpc 61e4f29b5ebc gitea/gitea:1.19.0 "/usr/bin/entrypoint…" 2 weeks ago Up 38 hours 22/tcp, 3000/tcp gitea 413621548b9a mysql/mysql-server:8.0.32 "/entrypoint.sh --de…" 2 weeks ago Up 38 hours (healthy) 3306/tcp, 33060-33061/tcp mysql8 [root@zmr-service ~]#
核心就是所有的docker容器都使用相同的网络。
1 2 3 4 5 6 7 8 9
# 创建网卡 docker network create -d bridge app_net
[root@zmr-service ~]# docker network ls NETWORK ID NAME DRIVER SCOPE 391b4ed84d89 app_net bridge local fab5d9edb87f bridge bridge local e976eb0945b9 host host local fa4d4514eb40 none null local
[root@zmr-service conf.d]# docker exec -it nginx ping gitea PING gitea (172.25.0.4): 56 data bytes 64 bytes from 172.25.0.4: icmp_seq=0 ttl=64 time=0.190 ms 64 bytes from 172.25.0.4: icmp_seq=1 ttl=64 time=0.134 ms 64 bytes from 172.25.0.4: icmp_seq=2 ttl=64 time=0.148 ms 64 bytes from 172.25.0.4: icmp_seq=3 ttl=64 time=0.133 ms 64 bytes from 172.25.0.4: icmp_seq=4 ttl=64 time=0.128 ms 64 bytes from 172.25.0.4: icmp_seq=5 ttl=64 time=0.130 ms 64 bytes from 172.25.0.4: icmp_seq=6 ttl=64 time=0.131 ms 64 bytes from 172.25.0.4: icmp_seq=7 ttl=64 time=0.130 ms
[root@zmr-service conf.d]# docker exec -it nginx ping waline PING waline (172.25.0.5): 56 data bytes 64 bytes from 172.25.0.5: icmp_seq=0 ttl=64 time=0.261 ms 64 bytes from 172.25.0.5: icmp_seq=1 ttl=64 time=0.136 ms 64 bytes from 172.25.0.5: icmp_seq=2 ttl=64 time=0.139 ms