Files
nexus/wiki/concepts/桥接网络.md
2026-04-22 19:20:32 +08:00

48 lines
1.6 KiB
Markdown
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.
# 桥接网络
## Type
- Concept
## Definition
桥接网络Bridge Network是 Docker 的默认网络模式,每个容器连接到宿主机上的 `docker0` 网桥,容器之间通过内部 Docker 网络通信,外部流量通过端口映射(-p访问。
## Mechanism
### 工作原理
```
宿主机网络
docker0 网桥 (172.17.0.1)
├── 容器A (172.17.0.2) ←→ 容器B (172.17.0.3)
└── 容器C (172.17.0.4)
```
### Docker Compose 配置
```yaml
network_mode: bridge # 使用 Docker 默认桥接网络
```
### 与 host 网络模式对比
| 特性 | bridge桥接 | host主机 |
|------|---------------|-------------|
| 网络命名空间 | 独立 | 共享宿主机 |
| 端口映射 | ✅ 支持 | ❌ 被忽略 |
| 网络隔离 | ✅ 容器间隔离 | ❌ 无隔离 |
| 性能 | 轻微NAT开销 | 最优(直接访问) |
| 适用场景 | Web服务、数据库 | 网络监控、代理 |
## Key Claims
- bridge 模式是 Docker 默认网络模式,无需显式配置
- 容器通过 docker0 网桥与宿主机和互联网通信
- 端口映射(-p在 bridge 模式下生效,将容器端口暴露到宿主机
- 容器间通过 DNS 自动解析服务名通信(同 docker-compose 服务名)
## Relationship to [[端口映射]]
[[端口映射]] 是桥接网络模式的核心能力——通过 iptables NAT 规则将容器端口转发到宿主机,实现外部访问。
## Relationship to [[LinuxServer.io]]
LinuxServer.io 所有官方 Docker 镜像默认使用 `network_mode: bridge`,这是其标准化配置模式的一部分,确保端口映射正常工作。
## Sources
- [[用docker安装transmission]]