详解docker nginx 容器启动挂载到本地

详解docker nginx 容器启动挂载到本地,第1张

详解dockernginx容器启动挂载到本地

本文对其中的关键细节进行了介绍。dockernginx容器在本地启动和挂载。根据示例代码,原文非常详细。对大家的学习培训或者工作都有一定的参考价值。有必要的朋友陪我去了解一下。

nginx容器中的第一个构造:

放入容器:

dockerexec-itb511b6049f57bash

查询容器的构造目录:其实每个容器就相当于一个单独的系统软件。

root@b511b6049f57:/#ls bindevhomelib64mntprocrunsrvtmpvar bootetclibmediaoptrootsbinsysusr

nginx的构建目录在容器中:

  • 日志位置:/var/log/nginx/
  • 配置文件位置:/etc/nginx/
  • 新项目位置:/usr/share/nginx/html
  • 如果要在本地添加位置,必须在本地将设备装入此容器:

    配置文件相对不方便。一般nginx只需要加载到nginx.conf中,在dokcer中,先加载nginx.conf,然后有一行include/etc/nginx/conf.d/*。nginx.conf中的conf,这是在conf.d目录中加载的配置文件。因此,设备只需要安装到conf.d并覆盖。

    在本地建立一个匹配的文件夹名和主配置文件nginx.conf:

    mkdir-p/home/test/nginx/{log,conf,html} touchnginx.conf

    Nginx.conf包含子配置文件(最后一行):

    usernginx; worker_processes1; error_log/var/log/nginx/error.logwarn; pid/var/run/nginx.pid; events{ worker_connections1024; } http{ include/etc/nginx/mime.types; default_typeapplication/octet-stream; log_formatmain'"$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.logmain; sendfileon; #tcp_nopushon; keepalive_timeout65; #gzipon; include/etc/nginx/conf.d/*.conf; }

    在conf下,建立default.conf的默认设置:

    server{ listen80; server_namelocalhost; #charsetkoi8-r; access_log/var/log/nginx/log/host.access.logmain; location/{ #root/data/nginx/html; root/usr/share/nginx/html; indexindex.htmlindex.htm; #autoindexon; #try_files$uri/index/index/page.html; #try_files$uri/index/map/page.html; } #error_page404/404.html; #redirectservererrorpagestothestaticpage/50x.html # error_page500502503504/50x.html; location=/50x.html{ root/usr/share/nginx/html; } location~/images{ default_typeapplication/json; return200'{"code":"A000000","message":"ok","timestamp":"20180307184426","data":{"isvip":"1","monthProList":[]}}'; } #proxythePHPscriptstoApachelisteningon127.0.0.1:80 # #location~\.php${ #proxy_passhttp://127.0.0.1; #} #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000 # #location~\.php${ #roothtml; #fastcgi_pass127.0.0.1:9000; #fastcgi_indexindex.php; #fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name; #includefastcgi_params; #} #denyaccessto.htaccessfiles,ifApache'sdocumentroot #concurswithnginx'sone # #location~/\.ht{ #denyall; #} }

    预先准备好上面的本地文件后,只需启动容器并将其挂载到本地配置文件:

    dockerrun--namedocker_nginx-d-p80: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/htmlnginx ### 第一个-v:挂载日志目录 第二个-v:挂载配备目录 第三个-v:挂载主配置文件 第四个-v:挂载新项目目录

    挂载后浏览主页:

    然后我浏览了一个之前大家默认写的位置/图片:


    重启nginx:

    dockerexec-itb511b6049f57nginx-sreload

    到目前为止,这篇关于dockernginx容器启动和挂载到本地的详细描述的文章已经在这里详细介绍过了。有关dockernginx启动和安装的大量信息,请搜索您以前的文章或再次访问下面的相关文章。期待你以后的申请!

    欢迎分享,转载请注明来源:内存溢出

    原文地址: http://outofmemory.cn/zz/774411.html

    (0)
    打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
    上一篇 2022-05-03
    下一篇 2022-05-03

    发表评论

    登录后才能评论

    评论列表(0条)

    保存