1.進入容器內部,拷貝default.conf和nginx.conf,儲存檔案,刪除注釋
2.在linux中,切換到跟目錄,建立4個檔案,這4個資料夾是用來和nginx容器內部的檔案進行掛載,docket給提供了這樣一種機制,方便修改容器內部的檔案。
[root@localhost nginx]# cd /
[root@localhost
/]# mkdir -p /opt/nginx/conf
[root@localhost
/]# mkdir -p /opt/nginx/conf.d
[root@localhost
/]# mkdir -p /opt/nginx/html
[root@localhost
/]# mkdir -p /opt/nginx/logs
3.利用finalshell工具,把nginx.conf檔案拷貝到/opt/nginx/conf,把default.conf拷貝到/opt/nginx/conf.d檔案中。
4.先停止,再刪除原來測試的nginx容器,先停止再刪除
[root@localhost
/]# docker stop 1916fcf894a5
[root@localhost
/]# docker rm 1916fcf894a5
5.建立nginx容器,並掛載linux對應的資料夾
[root@localhost
/]#docker run -d --privileged=
true
-p 80:80
-v /opt/nginx/conf/nginx.conf:
/etc/nginx/nginx.conf -v
/opt/nginx/conf.d/
default
.conf:
/etc/nginx/conf.d/
default
.conf -v
/opt/nginx/html:
/usr/share/nginx/html -v
/opt/nginx/logs:
/var/log/nginx --name nginx-
01 nginx:latest
6.驗證是否啟動成功
docker ps -a
Docker搭建Nginx環境
我這裡沒有指定版本號,所以拉取的最新的版本。然後是分別把nginx容器裡的配置檔案,日誌檔案,和html檔案對映到宿主機上。方便以後的更改。以我的為例 在 opt目錄新建了nginx資料夾,裡面分別有log,conf,html三個資料夾。接著從nginx容器裡把配置檔案複製到宿主機 opt ngin...
docker下的nginx實戰
使用docker搭建nginx服務 1.拉取nginx映象 docker pull nginx2.簡單啟動nginx服務 docker run d p 80 80 name nginx server nginx 引數說明 run 執行容器 d daemon 後台執行,守護程序 p 埠對映。順序為 宿...
docker下安裝Nginx的方法
一 環程式設計客棧境說明 二 拉取最新的 nginx 映象 拉取映象 docker pull nginx 檢視當前映象 docker images 查詢結果 repository tag image id created size nginx latest 8b89e48b5f15 7 hours ...