docker 网络互连


参考:

https://www.runoob.com/docker/docker-container-connection.html


ubuntu 的镜像没有自带ping,所以自己pull busybox

docker pull busybox


新建网络

docker network create -d bridge test-net


连接容器

运行一个容器并连接到新建的 test-net 网络:

docker run -itd --name test1 --network test-net busybox /bin/sh

docker run -itd --name test2 --network test-net busybox /bin/sh 


互相ping测试

docker exec -it test1 ping test2
PING test2 (192.168.48.3): 56 data bytes
64 bytes from 192.168.48.3: seq=0 ttl=64 time=0.084 ms

docker exec -it test2 ping test1
PING test1 (192.168.48.2): 56 data bytes
64 bytes from 192.168.48.2: seq=0 ttl=64 time=0.060 ms

posted on 2020-06-29 15:57  katago  阅读(158)  评论(0编辑  收藏  举报