docker_practice/advanced_network/port_mapping.md

58 lines
1.9 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.

## 宿
访访
### 访
NAT IP 使 `iptables`
NAT
```bash
$ sudo iptables -t nat -nL
...
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 172.17.0.0/16 !172.17.0.0/16
...
```
`172.17.0.0/16` MASQUERADE SNAT
### 访
访 `docker run` `-p` `-P`
`iptable` nat
使 `-P`
```bash
$ iptables -t nat -nL
...
Chain DOCKER (2 references)
target prot opt source destination
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:49153 to:172.17.0.2:80
```
使 `-p 80:80`
```bash
$ iptables -t nat -nL
Chain DOCKER (2 references)
target prot opt source destination
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:172.17.0.2:80
```
* `0.0.0.0` `-p IP:host_port:container_port` `-p IP::port` 访 IP
* IP Docker `/etc/docker/daemon.json`
```json
{
"ip": "0.0.0.0"
}
```