docker_practice/advanced_network/port_mapping.md

58 lines
1.9 KiB
Go
Raw Permalink Normal View History

# 宿
2014-09-05 07:50:54 +00:00
2014-09-18 09:38:20 +00:00
访访
2017-11-26 03:28:55 +00:00
## 访
2017-11-26 03:28:55 +00:00
NAT IP 使 `iptables`
2014-09-05 07:50:54 +00:00
NAT
2017-11-26 03:28:55 +00:00
2017-11-22 03:13:23 +00:00
```bash
2014-09-18 09:38:20 +00:00
$ sudo iptables -t nat -nL
2014-09-05 07:50:54 +00:00
...
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 172.17.0.0/16 !172.17.0.0/16
...
```
2017-11-26 03:28:55 +00:00
`172.17.0.0/16` MASQUERADE SNAT
2014-09-05 07:50:54 +00:00
## 访
2014-09-05 07:50:54 +00:00
访 `docker run` `-p` `-P`
2014-09-18 09:38:20 +00:00
`iptable` nat
2014-09-18 09:38:20 +00:00
使 `-P`
2017-11-26 03:28:55 +00:00
2017-11-22 03:13:23 +00:00
```bash
2014-09-18 09:38:20 +00:00
$ iptables -t nat -nL
2014-09-05 07:50:54 +00:00
...
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
2014-09-18 09:38:20 +00:00
```
使 `-p 80:80`
2017-11-26 03:28:55 +00:00
2017-11-22 03:13:23 +00:00
```bash
2014-09-18 09:38:20 +00:00
$ iptables -t nat -nL
2014-09-05 07:50:54 +00:00
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
```
2017-11-26 03:28:55 +00:00
2014-09-05 07:50:54 +00:00
2017-11-26 03:28:55 +00:00
2017-11-29 02:23:42 +00:00
* `0.0.0.0` `-p IP:host_port:container_port` `-p IP::port` 访 IP
2017-11-26 03:28:55 +00:00
2017-11-29 02:23:42 +00:00
* IP Docker `/etc/docker/daemon.json`
```json
{
"ip": "0.0.0.0"
}
```