docker_practice/underly/network.md

70 lines
4.5 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
Docker Linux veth pair
##
Docker
Linux
Docker `veth pair`
##
Docker
*
* docker0 veth65f9
* eth0
* eth0 veth65f9
使 eth0
`docker run` `--net` 4
* `--net=bridge`
* `--net=host` Docker 使访 root 访 D-bus使使 `--privileged=true`
* `--net=container:NAME_or_ID` Docker IP `lo`
* `--net=none` Docker
##
使 `--net=none` 访 Docker
`/bin/bash` `--net=none`
```bash
$ docker run -i -t --rm --net=none base /bin/bash
root@63f36fc01b5f:/#
```
id
```bash
$ docker inspect -f '{{.State.Pid}}' 63f36fc01b5f
2778
$ pid=2778
$ sudo mkdir -p /var/run/netns
$ sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid
```
IP
```bash
$ ip addr show docker0
21: docker0: ...
inet 172.17.42.1/16 scope global docker0
...
```
veth pair A B A `docker0`
```bash
$ sudo ip link add A type veth peer name B
$ sudo brctl addif docker0 A
$ sudo ip link set A up
```
B eth0 IP
```bash
$ 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
Docker eth0 A `docker0`
使 `ip netns exec`