Skip to content

Instantly share code, notes, and snippets.

@Blithe-Chiang
Last active April 27, 2021 12:32
Show Gist options
  • Save Blithe-Chiang/b825ea3d51a53a9863fccb078ba1d151 to your computer and use it in GitHub Desktop.
Save Blithe-Chiang/b825ea3d51a53a9863fccb078ba1d151 to your computer and use it in GitHub Desktop.
docker-compose 网络测试

Docker容器相互通信测试

通过 docker-compose 启动一系列的服务(以容器的形式),然后进到某个容器里 ping 其他的容器。

shooan/x: 基于 busybox,一直输出hello world

通过 docker exec --it /bin/sh box1

ping box2

version: "3.3"
# 启动两个服务
services:
box1:
# 设置容器名字
container_name: box1
image: shooan/hello
# 连接到new网络
networks:
- new # 添加到网络
box2:
# 除了名字之外,这两个服务是一样的
container_name: box2
image: shooan/hello
networks:
- new
# 配置网络
networks:
new: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment