docker_practice/network/port_mapping.md

80 lines
2.5 KiB
Go
Raw Normal View History

# 访
2017-11-23 10:42:43 +08:00
访 `-P` `-p`
使 `-P` Docker
使 `docker container ls` 32768 80 访 32768 访 NGINX
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -d -P nginx:alpine
2017-11-23 10:42:43 +08:00
$ docker container ls -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fae320d08268 nginx:alpine "/docker-entrypoint.…" 24 seconds ago Up 20 seconds 0.0.0.0:32768->80/tcp bold_mcnulty
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
`docker logs` 访
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker logs fa
172.17.0.1 - - [25/Aug/2020:08:34:04 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
```
2014-09-15 17:08:06 +08:00
2017-11-23 10:42:43 +08:00
`-p` `ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort`
2014-09-15 17:08:06 +08:00
##
2017-11-23 10:42:43 +08:00
使 `hostPort:containerPort` 80 80
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -d -p 80:80 nginx:alpine
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
2014-09-15 17:08:06 +08:00
##
2017-11-23 10:42:43 +08:00
使 `ip:hostPort:containerPort` 使 localhost 127.0.0.1
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -d -p 127.0.0.1:80:80 nginx:alpine
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
##
2017-11-23 10:42:43 +08:00
使 `ip::containerPort` localhost 80
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -d -p 127.0.0.1::80 nginx:alpine
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
使 `udp` `udp`
2017-11-13 18:54:38 +08:00
```bash
$ docker run -d -p 127.0.0.1:80:80/udp nginx:alpine
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
##
2017-11-23 10:42:43 +08:00
使 `docker port`
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker port fa 80
0.0.0.0:32768
2014-09-05 15:50:42 +08:00
```
2017-11-23 10:42:43 +08:00
2014-09-05 15:50:42 +08:00
* ip 使 `docker inspect` Docker
2017-11-23 10:42:43 +08:00
* `-p` 使
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
2017-11-23 10:42:43 +08:00
$ docker run -d \
-p 80:80 \
-p 443:443 \
nginx:alpine
2014-09-14 14:04:30 +08:00
```