先拉去镜像
docker pull nginx
先创建一个nginx
docker rum -p 8093:80 --name nginx -d nginx:latest
创建挂载目录
mkdir 你需要挂载的目录
docker cp ***配置文件就是你挂载目录的配置文件
创建nginx容器
docker run \
-p 8093:80 \
--name nginx \
-v /server/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /server/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /server/nginx/log:/var/log/nginx \
-v /server/nginx/html:/usr/share/nginx/html \
-v /ftp/:/ftp/ \
-d nginx:latest
-p 容器外端口号:容器内端口
--name 容器名
-v 容器外文件位置:容器内文件位置 //挂载
-v 同上 //挂载
-v 同上 //挂载
-v 同上 //挂载
-v 同上 //ftp目录
-d 镜像
server {
listen 80; #端口号
listen [::]:80;
server_name **.**.**.**; #ip
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /images/ { # http://localhost:port/images/ 匹配images路径
root /ftp/; #相当于http://localhost:port/ftp/images/
autoindex on;
}
问题记录:
注意挂载目录问题,有时候你确定文件存在,而且location正确还是爆404就有很大概率是挂载目录问题 。
2023-4-5 21:35