1.在本機新建配置文件docker_nginx.conf
server {
listen 7070;
server_name localhost;
charset utf-8;
location /files {
#在docker內(nèi)nginx的目錄
alias /home/files;
expires 1d;
allow all;
autoindex on;
}
2.啟動命令
docker run --name nginx -d -p 7070:7070 -v D:\dev\nginx-1.13.6\conf\docker_nginx.conf:/etc/nginx/nginx.conf -v D:\tools\files:/home/files nginx
說明:
- D:\dev\nginx-1.13.6\conf\docker_nginx.con是我本機配置文件的地址
- /etc/nginx/nginx.conf是docker nginx內(nèi)的配置文件地址
- D:\tools\files是我本地要共享文件夾的地址
- /home/files是在docker nginx內(nèi)映射的地址
3.結(jié)果
訪問localhost:7070/files可以看到最終映射的文件儒将。
執(zhí)行命令docker exec -it nginx bash
可以進入docker nginx內(nèi)部闹丐,結(jié)果如下
λ docker exec -it nginx bash
root@178a892f73ce:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@178a892f73ce:/# cd home/
root@178a892f73ce:/home# ls
files
root@178a892f73ce:/home# cd files/
root@178a892f73ce:/home/files# ls
2018-08-09 2018-08-13 2018-09-04
root@178a892f73ce:/home/files# exit
exit