docker_practice/underly/network.md

70 lines
4.5 KiB
Go
Raw Normal View History

## Docker
2014-09-21 13:40:10 +08:00
Docker Linux veth pair
2014-09-21 13:40:10 +08:00
###
Docker
2014-11-06 10:41:26 +08:00
Linux
2014-09-21 13:40:10 +08:00
Docker `veth pair`
2014-09-21 13:40:10 +08:00
###
Docker
2014-11-06 10:58:28 +08:00
*
* docker0 veth65f9
* eth0
* eth0 veth65f9
2014-09-21 13:40:10 +08:00
使 eth0
2014-09-21 13:40:10 +08:00
`docker run` `--net` 4
2014-09-21 13:40:10 +08:00
* `--net=bridge`
* `--net=host` Docker 使访 root 访 D-bus使使 `--privileged=true`
* `--net=container:NAME_or_ID` Docker IP `lo`
* `--net=none` Docker
2014-09-21 13:40:10 +08:00
###
使 `--net=none` 访 Docker
2014-09-21 13:40:10 +08:00
`/bin/bash` `--net=none`
2017-11-13 18:54:38 +08:00
```bash
$ docker run -i -t --rm --net=none base /bin/bash
2014-09-21 13:40:10 +08:00
root@63f36fc01b5f:/#
```
id
2017-11-13 18:54:38 +08:00
```bash
$ docker inspect -f '{{.State.Pid}}' 63f36fc01b5f
2014-09-21 13:40:10 +08:00
2778
$ pid=2778
$ sudo mkdir -p /var/run/netns
$ sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid
```
IP
2017-11-13 18:54:38 +08:00
```bash
2014-09-21 13:40:10 +08:00
$ ip addr show docker0
21: docker0: ...
inet 172.17.42.1/16 scope global docker0
...
```
veth pair A B A `docker0`
2017-11-13 18:54:38 +08:00
```bash
2014-09-21 13:40:10 +08:00
$ sudo ip link add A type veth peer name B
$ sudo brctl addif docker0 A
$ sudo ip link set A up
```
B eth0 IP
2017-11-13 18:54:38 +08:00
```bash
2014-09-21 13:40:10 +08:00
$ sudo ip link set B netns $pid
$ sudo ip netns exec $pid ip link set dev B name eth0
$ sudo ip netns exec $pid ip link set eth0 up
$ sudo ip netns exec $pid ip addr add 172.17.42.99/16 dev eth0
$ sudo ip netns exec $pid ip route add default via 172.17.42.1
```
Docker
2014-09-21 13:40:10 +08:00
2014-11-06 10:41:26 +08:00
Docker eth0 A `docker0`
2014-09-21 13:40:10 +08:00
使 `ip netns exec`