use nginx:alpine as demo

Signed-off-by: Kang Huaishuai <khs1994@khs1994.com>
pull/462/head
Kang Huaishuai 2020-08-25 16:54:59 +08:00
parent 5fb17c90e0
commit ee26243625
No known key found for this signature in database
GPG Key ID: 5E515022F565DA09
4 changed files with 37 additions and 43 deletions

View File

@ -12,7 +12,6 @@
docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba267838cc1b ubuntu:18.04 "/bin/bash" 30 minutes ago Exited (0) About a minute ago trusting_newton
98e5efa7d997 training/webapp:latest "python app.py" About an hour ago Exited (0) 34 minutes ago backstabbing_pike
```
`docker container start`

View File

@ -7,29 +7,27 @@
```bash
$ docker run -d -P \
--name web \
# -v /src/webapp:/opt/webapp \
--mount type=bind,source=/src/webapp,target=/opt/webapp \
training/webapp \
python app.py
# -v /src/webapp:/usr/share/nginx/html \
--mount type=bind,source=/src/webapp,target=/usr/share/nginx/html \
nginx:alpine
```
`/src/webapp` `/opt/webapp`便使 `-v` Docker 使 `--mount` Docker
`/src/webapp` `/usr/share/nginx/html`便使 `-v` Docker 使 `--mount` Docker
Docker `读写` `readonly` `只读`
```bash
$ docker run -d -P \
--name web \
# -v /src/webapp:/opt/webapp:ro \
--mount type=bind,source=/src/webapp,target=/opt/webapp,readonly \
training/webapp \
python app.py
# -v /src/webapp:/usr/share/nginx/html:ro \
--mount type=bind,source=/src/webapp,target=/usr/share/nginx/html,readonly \
nginx:alpine
```
`readonly` `只读` `/opt/webapp`
`readonly` `只读` `/usr/share/nginx/html`
```bash
/opt/webapp # touch new.txt
/usr/share/nginx/html # touch new.txt
touch: new.txt: Read-only file system
```
@ -48,7 +46,7 @@ $ docker inspect web
{
"Type": "bind",
"Source": "/src/webapp",
"Destination": "/opt/webapp",
"Destination": "/usr/share/nginx/html",
"Mode": "",
"RW": true,
"Propagation": "rprivate"

View File

@ -10,7 +10,7 @@
* `数据卷` 使
>`数据卷` 使 Linux mount `数据卷`
>`数据卷` 使 Linux mount
##
@ -23,6 +23,7 @@ $ docker volume create my-vol
```bash
$ docker volume ls
DRIVER VOLUME NAME
local my-vol
```
@ -46,15 +47,14 @@ $ docker volume inspect my-vol
`docker run` 使 `--mount` `数据卷` `docker run` `数据卷`
`web` `数据卷` `/webapp`
`web` `数据卷` `/usr/share/nginx/html`
```bash
$ docker run -d -P \
--name web \
# -v my-vol:/wepapp \
--mount source=my-vol,target=/webapp \
training/webapp \
python app.py
# -v my-vol:/usr/share/nginx/html \
--mount source=my-vol,target=/usr/share/nginx/html \
nginx:alpine
```
##
@ -73,7 +73,7 @@ $ docker inspect web
"Type": "volume",
"Name": "my-vol",
"Source": "/var/lib/docker/volumes/my-vol/_data",
"Destination": "/webapp",
"Destination": "/usr/share/nginx/html",
"Driver": "local",
"Mode": "",
"RW": true,

View File

@ -2,35 +2,33 @@
访 `-P` `-p`
使 `-P` Docker `49000~49900`
使 `-P` Docker
使 `docker container ls` 49155 5000 访 49155 访 web
使 `docker container ls` 32768 80 访 32768 访 NGINX
```bash
$ docker run -d -P training/webapp python app.py
$ docker run -d -P nginx:alpine
$ 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
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`
`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 -
$ 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` 5000 5000
使 `hostPort:containerPort` 80 80
```bash
$ docker run -d -p 5000:5000 training/webapp python app.py
$ docker run -d -p 80:80 nginx:alpine
```
@ -40,21 +38,21 @@ $ 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
$ docker run -d -p 127.0.0.1:80:80 nginx:alpine
```
##
使 `ip::containerPort` localhost 5000
使 `ip::containerPort` localhost 80
```bash
$ docker run -d -p 127.0.0.1::5000 training/webapp python app.py
$ docker run -d -p 127.0.0.1::80 nginx:alpine
```
使 `udp` `udp`
```bash
$ docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py
$ docker run -d -p 127.0.0.1:80:80/udp nginx:alpine
```
##
@ -62,12 +60,12 @@ $ 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.
$ docker port fa 80
0.0.0.0:32768
```
* ip 使 `docker inspect` Docker
* ip 使 `docker inspect` Docker
* `-p` 使
@ -75,8 +73,7 @@ $ docker port nostalgic_morse 5000
```bash
$ docker run -d \
-p 5000:5000 \
-p 3000:80 \
training/webapp \
python app.py
-p 80:80 \
-p 443:443 \
nginx:alpine
```