通过 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: {} |