docker_practice/advanced_network/ptp.md

46 lines
1.7 KiB
Go
Raw Normal View History

#
Docker `docker0`
2014-09-18 17:38:20 +08:00
`peer`
2014-09-18 17:38:20 +08:00
2
2017-11-13 18:54:38 +08:00
```bash
$ docker run -i -t --rm --net=none base /bin/bash
2014-09-05 15:50:54 +08:00
root@1f1f4c1f931a:/#
2017-11-13 18:54:38 +08:00
$ docker run -i -t --rm --net=none base /bin/bash
2014-09-05 15:50:54 +08:00
root@12e343489d2f:/#
```
2017-11-13 18:54:38 +08:00
```bash
$ docker inspect -f '{{.State.Pid}}' 1f1f4c1f931a
2014-09-05 15:50:54 +08:00
2989
2017-11-13 18:54:38 +08:00
$ docker inspect -f '{{.State.Pid}}' 12e343489d2f
2014-09-05 15:50:54 +08:00
3004
$ sudo mkdir -p /var/run/netns
$ sudo ln -s /proc/2989/ns/net /var/run/netns/2989
$ sudo ln -s /proc/3004/ns/net /var/run/netns/3004
```
`peer`
2017-11-13 18:54:38 +08:00
```bash
2014-09-05 15:50:54 +08:00
$ sudo ip link add A type veth peer name B
$ sudo ip link set A netns 2989
$ sudo ip netns exec 2989 ip addr add 10.1.1.1/32 dev A
$ sudo ip netns exec 2989 ip link set A up
$ sudo ip netns exec 2989 ip route add 10.1.1.2/32 dev A
$ sudo ip link set B netns 3004
$ sudo ip netns exec 3004 ip addr add 10.1.1.2/32 dev B
$ sudo ip netns exec 3004 ip link set B up
$ sudo ip netns exec 3004 ip route add 10.1.1.1/32 dev B
```
2 ping
2014-09-18 17:38:20 +08:00
`--net=none`
2014-09-05 15:50:54 +08:00
使 `--icc=false`