1. 程式人生 > 其它 >docker使用nginx,並進行掛載nginx.conf並將html資料夾定位到本地上

docker使用nginx,並進行掛載nginx.conf並將html資料夾定位到本地上

目標:docker拉取nginx,並將本地的nginx.conf和容器內的nginx.conf進行對映,講容器內的html資料夾和本地的資料夾進行對映。

主要命令是 docker -v 宿主機(資料夾/檔案):容器(資料夾/檔案)

現在宿主機建立

/usr/local/nginx {html/conf} 然後在conf資料夾裡面放置 nginx.conf檔案

然後,有一個關鍵的問題

這一個nginx.conf檔案,我是直接從官網中,拉取的nginx-1.8.tar.gz,然後我解壓獲取的nginx.con檔案

這裡我忽略了一個問題,就是檔案目錄的問題,這也是我後面踩的一個坑

因為容器內的html資料夾的位置在/usr/share/nginx/html中,而軟體中的html是在總資料夾下,所以 root 是 html, root : html

所以宿主機內的nginx.conf的root 必須更改為/usr/share/nginx/html,這樣子才可以指向容器內的html。

更改root之後,執行命令

docker run -dit -p 80:80 -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/html:/usr/share/nginx/html docker

然後宿主機的html資料夾就成為了容器指向的資料夾