参考:

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

相关文章:

  • 2022-02-27
  • 2021-11-15
  • 2021-12-18
  • 2021-10-01
  • 2021-06-11
  • 2021-06-09
  • 2021-04-18
  • 2021-09-09
猜你喜欢
  • 2021-07-10
  • 2022-02-14
  • 2021-04-21
  • 2021-05-22
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案