部分内容原文地址:

CSDN:wuzhangweiss:Docker中运行nginx并挂载本地目录到镜像中



1.Docker中运行nginx

直接一条命令:

docker run -d -p 8020:80 --name nginx --net=host -v /etc/localtime:/etc/localtime -v /root/software/nginx/html:/usr/share/nginx/html -v /root/software/nginx/conf:/etc/nginx -v /root/software/nginx/logs:/var/log/nginx nginx

需注意点:

  • 日志位置:/var/log/nginx/
  • 配置文件位置:/etc/nginx/
  • 项目位置:/usr/share/nginx/html

直接拉取的docker hub的nginx镜像,相关目录内容如上,到时候若需要挂载到宿主机相对应目录时,要记得将nginx.conf中相关路径对应对。

如项目位置,nginx.cong中对应的位置应该是/usr/share/nginx/html,访问路径时,先访问容器内的路径,然后根据容器内的路径在去挂载目录寻找文件。

2.配置文件

2.1 nginx.conf

因为有时候,nginx用户缺少权限,将user修改为root,提升权限。

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

2.2 default.conf

server {
listen 80;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
} #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;
} }

3、docker的镜像可以挂什么卷

docker run --name nginx01 -p 80:80 -v /everything/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /everything/nginx/html:/usr/share/nginx/html --restart always -d nginx

docker创建nginx的命令,从何地能看到nginx.conf挂载什么卷,目录结构等。

dockerfile提供的hub.docker:

ENV NGINX\_VERSION 1.7.4  

\# All our runtime and build dependencies, in alphabetical order (to ease maintenance)
RUN buildDeps=" \\
ca-certificates \\ curl \\ gcc \\ libc-dev-bin \\ libc6-dev \\ libexpat1-dev \\ libfontconfig1-dev \\ libfreetype6-dev \\ libgd-dev \\ libgd2-dev \\ libgeoip-dev \\ libice-dev \\ libjbig-dev \\ libjpeg8-dev \\ liblzma-dev \\ libpcre3-dev \\ libperl-dev \\ libpng12-dev \\ libpthread-stubs0-dev \\ libsm-dev \\ libssl-dev \\ libssl-dev \\ libtiff5-dev \\ libvpx-dev \\ libx11-dev \\ libxau-dev \\ libxcb1-dev \\ libxdmcp-dev \\ libxml2-dev \\ libxpm-dev \\ libxslt1-dev \\ libxt-dev \\ linux-libc-dev \\ make \\ manpages-dev \\ x11proto-core-dev \\ x11proto-input-dev \\ x11proto-kb-dev \\ xtrans-dev \\ zlib1g-dev \\ "; \\
apt-get update && apt-get install \-y \--no-install-recommends $buildDeps && rm \-rf /var/lib/apt/lists/\* \\
&& curl \-SL "http://nginx.org/download/nginx-$NGINX\_VERSION.tar.gz" \-o nginx.tar.gz \\
&& curl \-SL "http://nginx.org/download/nginx-$NGINX\_VERSION.tar.gz.asc" \-o nginx.tar.gz.asc \\
&& gpg \--verify nginx.tar.gz.asc \\
&& mkdir \-p /usr/src/nginx \\
&& tar \-xvf nginx.tar.gz \-C /usr/src/nginx \--strip-components=1 \\
&& rm nginx.tar.gz\* \\
&& cd /usr/src/nginx \\
&& ./configure \\
\--user=www-data \\
\--group=www-data \\
\--prefix=/usr/local/nginx \\
\--conf-path=/etc/nginx.conf \\
\--http-log-path=/proc/self/fd/1 \\
\--error-log-path=/proc/self/fd/2 \\
\--with-http\_addition\_module \\
\--with-http\_auth\_request\_module \\
\--with-http\_dav\_module \\
\--with-http\_geoip\_module \\
\--with-http\_gzip\_static\_module \\
\--with-http\_image\_filter\_module \\
\--with-http\_perl\_module \\
\--with-http\_realip\_module \\
\--with-http\_spdy\_module \\
\--with-http\_ssl\_module \\
\--with-http\_stub\_status\_module \\
\--with-http\_sub\_module \\
\--with-http\_xslt\_module \\
\--with-ipv6 \\
\--with-mail \\
\--with-mail\_ssl\_module \\
\--with-pcre-jit \\
&& make \-j"$(nproc)" \\
&& make install \\
&& cd / \\
&& rm \-r /usr/src/nginx \\
&& chown \-R www-data:www-data /usr/local/nginx \\
&& { \\
echo; \\
echo '# stay in the foreground so Docker has a process to track'; \\
echo 'daemon off;'; \\
} \>> /etc/nginx.conf \\
&& apt-get purge \-y \--auto-remove $buildDeps ENV PATH /usr/local/nginx/sbin:$PATH
WORKDIR /usr/local/nginx/html \# TODO USER www-data EXPOSE 80
CMD \["nginx"\]

Docker中运行nginx的更多相关文章

  1. Docker中运行nginx并挂载本地目录到镜像中

    1.1 从hup上pull镜像1.2 创建将要挂载的目录1.3 先要有配置文件才能启动容器1.3.1 vim /data/nginx/conf/nginx.conf1.3.2 vim /data/ng ...

  2. 滚动 docker 中的 nginx 日志

    Nginx 自己没有处理日志的滚动问题,它把这个球踢给了使用者.一般情况下,你可以使用 logrotate 工具来完成这个任务,或者如果你愿意,你可以写各式各样的脚本完成同样的任务.本文笔者介绍如何滚 ...

  3. Docker中运行MySQL5.7并挂载宿主机目录到镜像

    原文:Docker中运行MySQL5.7并挂载宿主机目录到镜像 1.1 拉取mysql镜像 docker pull mysql:5.7 1.2 创建用于挂载的目录 mkdir -p /data/mys ...

  4. docker 运行jenkins及vue项目与springboot项目(五.jenkins打包springboot服务且在docker中运行)

    docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...

  5. 在docker中运行ASP.NET Core Web API应用程序

    本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过程中,也会对docker的使用进行一些简单的描述.对于.NET Cor ...

  6. .NET Core Web 应用部署到 Docker 中运行

    环境介绍 : 虚拟机:VirtualBox 5.1.6 系 统:Ubuntu 16.04.1 LTS 系统准备完成后可以使用 sudo apt-get udpate 和 sudo apt-get up ...

  7. docker中运行ASP.NET Core Web API

    在docker中运行ASP.NET Core Web API应用程序 本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过 ...

  8. 在Docker中运行torch版的neural style

    相关的代码都在Github上,请参见我的Github,https://github.com/lijingpeng/deep-learning-notes 敬请多多关注哈~~~ 在Docker中运行to ...

  9. ASP.NET Core 网站在Docker中运行

    Docker作为新一代的虚拟化方式,未来肯定会得到广泛的应用,传统虚拟机的部署方式要保证开发环境.测试环境.UAT环境.生产环境的依赖一致性,需要大量的运维人力,使用Docker我们可以实现一次部署, ...

随机推荐

  1. c通过ctfshow学习php反序列化

    web254 web255 web256 web257 web258 web259 web260 web262 web263 web264 web265 web266 web254 error_rep ...

  2. python之random 、os 、sys 模块

    一.random模块 import random print(random.random())#(0,1)----float 大于0且小于1之间的小数 print(random.randint(1,3 ...

  3. 两个很赞的用法(count函数里的表达式+计算时间间隔)

    1.count函数里写表达式 #无效写法,这样写不会判断表达式(ischecked=0),会全部列出来 SELECT cardid FROM search_detail GROUP BY cardid ...

  4. LeetCode105 从前序和中序序列构造二叉树

    题目描述: 根据一棵树的前序遍历与中序遍历构造二叉树. 注意:你可以假设树中没有重复的元素. 例如,给出 前序遍历 preorder = [3,9,20,15,7] 中序遍历 inorder = [9 ...

  5. Deep Learn I'm back.

    Intorduction: 时隔好几个月,我准备重新进入Deep Learning 的领域.昨天和老师聊了很多,之前觉得我做的工作就是排列组合,在水论文,灌水.但老师却说:这也是为将来的研究打基础. ...

  6. 【Java】单例模式(Singleton)

    重新搞一波 复习巩固 简单记录 慕课网 Java工程师 文章目录 单例概述 设计模式 单例模式(Singleton) 参考资料 单例概述 Singleton Pattern 单例模式是Java中最简单 ...

  7. DG主备切换遇到not allwod或者RESOLVABLE GAP解决办法

    今天做switchover,环境是11.2.0.3+OEL5.7,开始时主备库状态都是正常的,符合直接切换条件: 主库: SQL> select open_mode,database_role, ...

  8. 【Oracle】查询锁的相关SQL

    --查看有锁的进程 select t2.username,t2.sid,t2.serial#,t2.logon_time,t2.state from v$locked_object t1,v$sess ...

  9. 攻防世界—pwn—level2

    题目分析 题目提示 下载文件后首先使用checksec检查文件保护机制 使用ida打开,查看伪代码 搜索字符串发现/bash/sh 信息收集 偏移量 system的地址 /bin/sh的地址 编写脚本 ...

  10. mysql—make_set函数

    使用格式:MAKE_SET(bits,str1,str2,-) 1 返回一个设定值(含子字符串分隔字符串","字符),在设置位的相应位的字符串.str1对应于位0,str2到第1位 ...