docker_practice/network/linking.md

68 lines
2.1 KiB
Go
Raw Permalink Normal View History

#
2017-11-23 10:42:43 +08:00
`Docker` 使使 `--link` 使
2017-11-30 18:22:16 +08:00
Docker Docker 使 `--link`
##
2017-11-23 10:42:43 +08:00
Docker
2017-11-13 18:54:38 +08:00
```bash
2017-11-23 10:42:43 +08:00
$ docker network create -d bridge my-net
2014-09-05 15:50:42 +08:00
```
2017-11-30 18:22:16 +08:00
`-d` Docker `bridge` `overlay` `overlay` [Swarm mode](../swarm_mode/)
##
2014-09-05 15:50:42 +08:00
2017-11-30 18:22:16 +08:00
`my-net`
2014-09-18 15:55:24 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -it --rm --name busybox1 --network my-net busybox sh
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
2017-11-30 18:22:16 +08:00
`my-net`
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -it --rm --name busybox2 --network my-net busybox sh
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker container ls
2017-11-23 10:42:43 +08:00
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b47060aca56b busybox "sh" 11 minutes ago Up 11 minutes busybox2
8720575823ec busybox "sh" 16 minutes ago Up 16 minutes busybox1
```
2017-11-23 10:42:43 +08:00
`ping` `busybox1` `busybox2`
2017-11-23 10:42:43 +08:00
`busybox1`
2014-09-05 15:50:42 +08:00
2017-11-13 18:54:38 +08:00
```bash
2017-11-23 10:42:43 +08:00
/ # ping busybox2
PING busybox2 (172.19.0.3): 56 data bytes
64 bytes from 172.19.0.3: seq=0 ttl=64 time=0.072 ms
64 bytes from 172.19.0.3: seq=1 ttl=64 time=0.118 ms
```
2017-11-30 18:22:16 +08:00
ping `busybox2` `172.19.0.3`
2017-11-23 10:42:43 +08:00
`busybox2` `ping busybox1`
2017-11-13 18:54:38 +08:00
```bash
2017-11-23 10:42:43 +08:00
/ # ping busybox1
PING busybox1 (172.19.0.2): 56 data bytes
64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.064 ms
64 bytes from 172.19.0.2: seq=1 ttl=64 time=0.143 ms
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
`busybox1` `busybox2`
2017-11-23 12:59:13 +08:00
## Docker Compose
2017-11-23 12:59:13 +08:00
使 [Docker Compose](../compose)