启动Nginx
现启动一个nginx进去现熟悉一下
docker run -d -p 80:80 --name nginx01 nginx
进入容器
[root@localhost ~]
root@bd5284328baf:/etc/nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@bd5284328baf:/etc/nginx
必须知道文件位置
/etc/nginx
/usr/share/nginx/html
/var/log/nginx
挂载网页目录
[root@localhost ~]
[root@localhost home]
[root@localhost home]
输入:
<h1>hello world<h1>
docker run -d \
-p 8080:80 \
-v /home/nginx01/html:/usr/share/nginx/html \
--name nginx01 \
nginx
挂载配置文件
需要注意的是:/etc/nginx 不能直接挂载,挂载之后无法启动; 重新启动一个新的容器,这次不仅映射网页目录,还要映射配置目录和日志目录。
docker rm -f nginx01
[root@localhost nginx01]
/home/nginx01
docker run -d \
-p 8080:80 \
--name nginx01 \
-v /home/nginx01/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx01/html:/usr/share/nginx/html \
-v /home/nginx01/logs:/var/log/nginx \
nginx
验证配置文件
刷新几次看看日志
[root@localhost logs]
10.5.1.200 - - [09/Aug/2021:13:32:24 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67" "-"
10.5.1.200 - - [09/Aug/2021:13:32:25 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67" "-"
10.5.1.200 - - [09/Aug/2021:13:32:26 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67" "-"
10.5.1.200 - - [09/Aug/2021:13:32:26 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67" "-"
10.5.1.200 - - [09/Aug/2021:13:32:26 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67" "-"
10.5.1.200 - - [09/Aug/2021:13:32:26 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67" "-"
10.5.1.200 - - [09/Aug/2021:13:32:27 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67" "-"
[root@localhost logs]
可能用到的命令
docker exec -it nginx01 /bin/bash
docker rm -f $(docker ps -aq)
|