Docker中怎么運行nginx并掛載本地目錄到鏡像中

這篇“Docker中怎么運行nginx并掛載本地目錄到鏡像中”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內(nèi)容,內(nèi)容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Docker中怎么運行nginx并掛載本地目錄到鏡像中”文章吧。

10多年的鄠邑網(wǎng)站建設經(jīng)驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。全網(wǎng)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設備顯示端的尺寸不同,自動調(diào)整鄠邑建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)公司從事“鄠邑網(wǎng)站設計”,“鄠邑網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。

創(chuàng)新互聯(lián)網(wǎng)站建設公司是一家服務多年做網(wǎng)站建設策劃設計制作的公司,為廣大用戶提供了成都網(wǎng)站設計、成都網(wǎng)站制作,成都網(wǎng)站設計,廣告投放,成都做網(wǎng)站選創(chuàng)新互聯(lián),貼合企業(yè)需求,高性價比,滿足客戶不同層次的需求一站式服務歡迎致電。

1 從hup上pull鏡像

docker pull nginx

2 創(chuàng)建將要掛載的目錄

mkdir -p /data/nginx/{conf,conf.d,html,logs}

3 先要有配置文件才能啟動容器

3.1 vim /data/conf/nginx.conf

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid    /var/run/nginx.pid;


events {
  worker_connections 1024;
}


http {
  include    /etc/nginx/mime.types;
  default_type application/octet-stream;

  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';

  access_log /var/log/nginx/access.log main;

  sendfile    on;
  #tcp_nopush   on;

  keepalive_timeout 65;

  #gzip on;

  include /etc/nginx/conf.d/*.conf;
}

3.2 vim /data/nginx/conf.d/default.conf

server { 
  listen    80; 
  server_name localhost; 
 
  #charset koi8-r; 
  #access_log /var/log/nginx/log/host.access.log main; 
 
  location / { 
    root  /data/nginx/html; 
    # root  /usr/nginx/html; 
    index index.html index.htm; 
    autoindex on; 
  try_files $uri /index/index/page.html; 
    #try_files $uri /index/map/page.html; 
  } 
 
  #error_page 404       /404.html; 
 
  # redirect server error pages to the static page /50x.html 
  # 
  error_page  500 502 503 504 /50x.html; 
  location = /50x.html { 
    root  /usr/share/nginx/html; 
  } 
 
  # proxy the php scripts to apache listening on 127.0.0.1:80 
  # 
  #location ~ \.php$ { 
  #  proxy_pass  http://127.0.0.1; 
  #} 
 
  # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 
  # 
  #location ~ \.php$ { 
  #  root      html; 
  #  fastcgi_pass  127.0.0.1:9000; 
  #  fastcgi_index index.php; 
  #  fastcgi_param script_filename /scripts$fastcgi_script_name; 
  #  include    fastcgi_params; 
  #} 
 
  # deny access to .htaccess files, if apache's document root 
  # concurs with nginx's one 
  # 
  #location ~ /\.ht { 
  #  deny all; 
  #} 
}

4 啟動容器

#將容器中nginx的80端口映射到本地的81端口
docker run --name nginx81 -d -p 81:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d -d nginx:latest

5 查看啟動的容器

[root@dc01 ~]# docker ps
container id image command created status ports names
fa56f865bd26 nginx:latest "nginx -g 'daemon of…" 4 weeks ago up 3 seconds 0.0.0.0:80->80/tcp vigilant_swirles
[root@dc01 ~]#

6 網(wǎng)頁訪問nginx

Docker中怎么運行nginx并掛載本地目錄到鏡像中

以上就是關于“Docker中怎么運行nginx并掛載本地目錄到鏡像中”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關的知識內(nèi)容,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當前標題:Docker中怎么運行nginx并掛載本地目錄到鏡像中
網(wǎng)頁路徑:http://bm7419.com/article0/igchoo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)站導航、小程序開發(fā)、定制開發(fā)、網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設