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 docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 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 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` `docker container start`

View File

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

View File

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

View File

@ -2,35 +2,33 @@
访 `-P` `-p` 访 `-P` `-p`
使 `-P` Docker `49000~49900` 使 `-P` Docker
使 `docker container ls` 49155 5000 访 49155 访 web 使 `docker container ls` 32768 80 访 32768 访 NGINX
```bash ```bash
$ docker run -d -P training/webapp python app.py $ docker run -d -P nginx:alpine
$ docker container ls -l $ docker container ls -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 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 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 ```bash
$ docker logs -f nostalgic_morse $ docker logs fa
* Running on http://0.0.0.0:5000/ 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" "-"
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` `-p` `ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort`
## ##
使 `hostPort:containerPort` 5000 5000 使 `hostPort:containerPort` 80 80
```bash ```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 使 `ip:hostPort:containerPort` 使 localhost 127.0.0.1
```bash ```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 ```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` 使 `udp` `udp`
```bash ```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` 使 `docker port`
```bash ```bash
$ docker port nostalgic_morse 5000 $ docker port fa 80
127.0.0.1:49155. 0.0.0.0:32768
``` ```
* ip 使 `docker inspect` Docker * ip 使 `docker inspect` Docker
* `-p` 使 * `-p` 使
@ -75,8 +73,7 @@ $ docker port nostalgic_morse 5000
```bash ```bash
$ docker run -d \ $ docker run -d \
-p 5000:5000 \ -p 80:80 \
-p 3000:80 \ -p 443:443 \
training/webapp \ nginx:alpine
python app.py
``` ```