欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解docker nginx 容器啟動掛載到本地

 更新時(shí)間:2020年07月23日 09:39:27   作者:memory丶o(jì)f  
這篇文章主要介紹了詳解docker nginx 容器啟動掛載到本地,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

首先nginx容器內(nèi)部的結(jié)構(gòu):

進(jìn)入容器:

docker exec -it b511b6049f57 bash

查看容器的結(jié)構(gòu)目錄:其實(shí)每一個(gè)容器就相當(dāng)于一個(gè)獨(dú)立的系統(tǒng)。

root@b511b6049f57:/# ls
bin  dev home lib64	mnt proc run	 srv tmp var
boot etc lib	 media	opt root sbin sys usr

nginx的結(jié)構(gòu)目錄在容器中:

  • 日志位置:/var/log/nginx/
  • 配置文件位置:/etc/nginx/
  • 項(xiàng)目位置:/usr/share/nginx/html

如果你想在本地去添加location 需要把這些容器中的配置掛載到本地:

配置文件相對來說有點(diǎn)麻煩,一般nginx只需要加載nginx.conf就可以了,在dokcer中,是首先加載nginx.conf,然后在nginx.conf有這么一行include /etc/nginx/conf.d/*.conf;,就是加載conf.d目錄下的配置文件。所以對于配置只需要掛載到conf.d,覆蓋掉即可。

在本地創(chuàng)建對應(yīng)的文件夾和主配置文件nginx.conf:

mkdir -p /home/test/nginx/{log,conf,html}
touch nginx.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" "$http_host" "[$time_local]" "$request" "$status" "$body_bytes_sent" '
          '"$bytes_sent" "$gzip_ratio" "$http_referer" "$http_user_agent" "$http_x_forwarded_for" '
          '"$upstream_addr" "$upstream_response_time" "$request_time" "$request_body" "$http_authorization" ';
  access_log /var/log/nginx/access.log main;

  sendfile    on;
  #tcp_nopush   on;

  keepalive_timeout 65;

  #gzip on;

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

在 conf下創(chuàng)建一個(gè)默認(rèn)的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/share/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;
  }

  location ~ /images {
    default_type              application/json;
    return 200 '{"code": "A000000", "message": "ok", "timestamp": "20180307184426", "data": {"isvip": "1", "monthProList": []}}';
  }

  # 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;
  #}
}

準(zhǔn)備完成上面的本地文件以后開始啟動容器掛載到本地相關(guān)配置文件:

docker run --name docker_nginx -d -p 80:80 \
-v /home/test/nginx/log:/var/log/nginx \
-v /home/test/nginx/conf:/etc/nginx/conf.d \
-v /home/test/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/test/nginx/html:/usr/share/nginx/html nginx

###
  第一個(gè)-v:掛載日志目錄
  第二個(gè)-v:掛載配置目錄
  第三個(gè)-v:掛載主配置文件
  第四個(gè)-v:掛載項(xiàng)目目錄

掛載完成以后訪問主頁面:

然后在訪問我們之前在default寫的一個(gè)location /images:


重啟nginx:

docker exec -it b511b6049f57 nginx -s reload

到此這篇關(guān)于詳解docker nginx 容器啟動掛載到本地的文章就介紹到這了,更多相關(guān)docker nginx啟動掛載內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用docker極簡打包java.jar鏡像并啟動的操作步驟

    使用docker極簡打包java.jar鏡像并啟動的操作步驟

    這篇文章主要介紹了用docker極簡打包java.jar鏡像并啟動,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08
  • docker在已有的tomcat鏡像上打新的鏡像的Dockerfile編寫說明介紹

    docker在已有的tomcat鏡像上打新的鏡像的Dockerfile編寫說明介紹

    這篇文章主要介紹了docker在已有的tomcat鏡像上打新的鏡像的Dockerfile編寫說明介紹,需要的朋友可以參考下
    2016-10-10
  • Linux新建用戶并允許docker及docker基本命令

    Linux新建用戶并允許docker及docker基本命令

    這篇文章給大家介紹了Linux新建用戶并允許docker及docker的容器創(chuàng)建及基本命令講解,需要的朋友參考下本文吧
    2017-12-12
  • Docker overlay 網(wǎng)絡(luò)搭建的方法

    Docker overlay 網(wǎng)絡(luò)搭建的方法

    Overlay網(wǎng)絡(luò)是指通過在現(xiàn)有網(wǎng)絡(luò)上疊加一個(gè)軟件定義的邏輯網(wǎng)絡(luò),這篇文章主要介紹了Docker overlay 網(wǎng)絡(luò)搭建的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • Docker清理命令之如何刪除所有的鏡像和容器

    Docker清理命令之如何刪除所有的鏡像和容器

    這篇文章主要介紹了Docker清理命令之如何刪除所有的鏡像和容器問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Docker 學(xué)習(xí)文檔(知識結(jié)構(gòu)整理)

    Docker 學(xué)習(xí)文檔(知識結(jié)構(gòu)整理)

    這篇文章主要介紹了Docker 學(xué)習(xí)文檔的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • 關(guān)于docker?cgroups資源限制的問題

    關(guān)于docker?cgroups資源限制的問題

    cgroups是一個(gè)非常強(qiáng)大的linux內(nèi)核工具,他不僅可以限制被namespace隔離起來的資源,還可以為資源設(shè)置權(quán)重、計(jì)算使用量,這篇文章主要介紹了docker?cgroups資源限制,需要的朋友可以參考下
    2022-09-09
  • centos下docker安裝及springboot遠(yuǎn)程發(fā)布docker的方法

    centos下docker安裝及springboot遠(yuǎn)程發(fā)布docker的方法

    這篇文章主要介紹了centos下docker安裝及springboot遠(yuǎn)程發(fā)布docker的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • 解決docker運(yùn)行tomcat提示找不到文件的問題

    解決docker運(yùn)行tomcat提示找不到文件的問題

    這篇文章主要介紹了docker運(yùn)行tomcat提示找不到文件的問題及解決方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-03-03
  • 使用 Docker 部署 Apache Spark 集群的過程

    使用 Docker 部署 Apache Spark 集群的過程

    本文介紹了如何使用Docker和DockerCompose快速部署一個(gè)包含一個(gè)Master節(jié)點(diǎn)和兩個(gè)Worker節(jié)點(diǎn)的Spark集群,通過創(chuàng)建docker-compose.yml文件并執(zhí)行相關(guān)命令,可以實(shí)現(xiàn)集群的構(gòu)建和啟動,感興趣的朋友一起看看吧
    2025-02-02

最新評論