案例:使用 link 关联后台与数据库
1、创建 test1 容器
docker run -d --name test1 hub.c.163.com/library/busybox /bin/sh -c "while true; do sleep 3600; done"
docker exec test1 ip a
2、创建 test2 并关联到 test1 上
docker run -d --name test2 --link test1 hub.c.163.com/library/busybox /bin/sh -c "while true; do sleep 3600; done"
3、进入test2 容器内: docker exec -it test2 /bin/sh
可以使用 ping test1 即可访问 test1
如果test1是 mysql 服务 可以使用 test1:3306 即可访问数据库
4、论证link链接是单向