docker_practice/network/port_mapping.md

83 lines
2.6 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.

## 访
访 `-P` `-p`
使 `-P` Docker `49000~49900`
使 `docker container ls` 49155 5000 访 49155 访 web
```bash
$ docker run -d -P training/webapp python app.py
$ docker container ls -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc533791f3f5 training/webapp:latest python app.py 5 seconds ago Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse
```
`docker logs`
```bash
$ docker logs -f nostalgic_morse
* Running on http://0.0.0.0:5000/
10.0.2.2 - - [23/May/2014 20:16:31] "GET / HTTP/1.1" 200 -
10.0.2.2 - - [23/May/2014 20:16:31] "GET /favicon.ico HTTP/1.1" 404 -
```
`-p` `ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort`
###
使 `hostPort:containerPort` 5000 5000
```bash
$ docker run -d -p 5000:5000 training/webapp python app.py
```
###
使 `ip:hostPort:containerPort` 使 localhost 127.0.0.1
```bash
$ docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py
```
###
使 `ip::containerPort` localhost 5000
```bash
$ docker run -d -p 127.0.0.1::5000 training/webapp python app.py
```
使 `udp` `udp`
```bash
$ docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py
```
###
使 `docker port`
```bash
$ docker port nostalgic_morse 5000
127.0.0.1:49155.
```
* ip 使 `docker inspect` Docker
* `-p` 使
```bash
$ docker run -d \
-p 5000:5000 \
-p 3000:80 \
training/webapp \
python app.py
```