docker_practice/network/port_mapping.md

80 lines
2.5 KiB
Go
Raw Permalink 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.

# 访
访 `-P` `-p`
使 `-P` Docker
使 `docker container ls` 32768 80 访 32768 访 NGINX
```bash
$ docker run -d -P nginx:alpine
$ 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
```
`docker logs` 访
```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" "-"
```
`-p` `ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort`
##
使 `hostPort:containerPort` 80 80
```bash
$ docker run -d -p 80:80 nginx:alpine
```
##
使 `ip:hostPort:containerPort` 使 localhost 127.0.0.1
```bash
$ docker run -d -p 127.0.0.1:80:80 nginx:alpine
```
##
使 `ip::containerPort` localhost 80
```bash
$ docker run -d -p 127.0.0.1::80 nginx:alpine
```
使 `udp` `udp`
```bash
$ docker run -d -p 127.0.0.1:80:80/udp nginx:alpine
```
##
使 `docker port`
```bash
$ docker port fa 80
0.0.0.0:32768
```
* ip 使 `docker inspect` Docker
* `-p` 使
```bash
$ docker run -d \
-p 80:80 \
-p 443:443 \
nginx:alpine
```