docker_practice/network/port_mapping.md

83 lines
2.6 KiB
Go
Raw Normal View History

## 访
2017-11-23 10:42:43 +08:00
访 `-P` `-p`
2017-11-23 10:42:43 +08:00
使 `-P` Docker `49000~49900`
使 `docker container ls` 49155 5000 访 49155 访 web
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -d -P training/webapp python app.py
2017-11-23 10:42:43 +08:00
$ docker container ls -l
2014-09-05 15:50:42 +08:00
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
```
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 -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 -
```
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` 5000 5000
2017-11-23 10:42:43 +08:00
2017-11-13 18:54:38 +08:00
```bash
$ docker run -d -p 5000:5000 training/webapp python app.py
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:5000:5000 training/webapp python app.py
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 5000
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::5000 training/webapp python app.py
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:5000:5000/udp training/webapp python app.py
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
2014-09-05 15:50:42 +08:00
$ docker port nostalgic_morse 5000
127.0.0.1:49155.
```
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 5000:5000 \
-p 3000:80 \
training/webapp \
python app.py
2014-09-14 14:04:30 +08:00
```