docker_practice/network/linking.md

68 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#
`Docker` 使使 `--link` 使
Docker Docker 使 `--link`
##
Docker
```bash
$ docker network create -d bridge my-net
```
`-d` Docker `bridge` `overlay` `overlay` [Swarm mode](../swarm_mode/)
##
`my-net`
```bash
$ docker run -it --rm --name busybox1 --network my-net busybox sh
```
`my-net`
```bash
$ docker run -it --rm --name busybox2 --network my-net busybox sh
```
```bash
$ docker container ls
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
```
`ping` `busybox1` `busybox2`
`busybox1`
```bash
/ # 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
```
ping `busybox2` `172.19.0.3`
`busybox2` `ping busybox1`
```bash
/ # 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
```
`busybox1` `busybox2`
## Docker Compose
使 [Docker Compose](../compose)