docker_practice/advanced_network/bridge.md
Kang HuaiShuai 5cb92f63cf
Update title style
Signed-off-by: Kang HuaiShuai <khs1994@khs1994.com>
2019-11-06 14:58:03 +08:00

46 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 自定义网桥
除了默认的 `docker0` 网桥用户也可以指定网桥来连接各个容器
在启动 Docker 服务的时候使用 `-b BRIDGE``--bridge=BRIDGE` 来指定使用的网桥
如果服务已经运行那需要先停止服务并删除旧的网桥
```bash
$ sudo systemctl stop docker
$ sudo ip link set dev docker0 down
$ sudo brctl delbr docker0
```
然后创建一个网桥 `bridge0`
```bash
$ sudo brctl addbr bridge0
$ sudo ip addr add 192.168.5.1/24 dev bridge0
$ sudo ip link set dev bridge0 up
```
查看确认网桥创建并启动
```bash
$ ip addr show bridge0
4: bridge0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state UP group default
link/ether 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
inet 192.168.5.1/24 scope global bridge0
valid_lft forever preferred_lft forever
```
Docker 配置文件 `/etc/docker/daemon.json` 中添加如下内容即可将 Docker 默认桥接到创建的网桥上
```json
{
"bridge": "bridge0",
}
```
启动 Docker 服务
新建一个容器可以看到它已经桥接到了 `bridge0`
可以继续用 `brctl show` 命令查看桥接的信息另外在容器中可以使用 `ip addr` `ip route` 命令来查看 IP 地址配置和路由信息