Docker-Dockerfile自定义NGINX镜像

  1. 下载需要的安装包
    1. wget https://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz
    2. wget http://nginx.org/download/nginx-1.14.0.tar.gz
  2. DockerFile 命令解析
    1. FROM 它的妈妈是谁(基础镜像)
    2. MAINTAINER 告诉别人你创造了它(维护者信息)
    3. RUN 你想让它干嘛(把命令前面加上RUN)
    4. ADD 往它肚子里面放点文件(COPY文件,会自动解压)
    5. WORKDIR 我是cd,今天刚化了妆(当前工作目录)
    6. VOLUME 给我一个存放行礼的地方(目录挂载)
    7. EXPOSE 我要打开的门是啥(端口)
    8. CMD 指定启动容器时默认执行的命令
    9. ENV 指定环境变量,在镜像生成过程中会被后续RUN指令使用,在镜像启动的容器中也会存在
  3. 创建Dockerfile(名字不能换)
    1. mkdir Dockerfile
    2. # This is My first Dockerfile
      # Version 1.0
      # Author: Xupx
      
      #Base image
      FROM centos
      
      #MAINTAINER
      MAINTAINER Xupx
      
      #ADD
      ADD pcre-8.37.tar.gz /usr/local/src
      ADD nginx-1.14.0.tar.gz /usr/local/src
      
      #RUN
      RUN yum install -y wget gcc gcc-c++ make openssl-devel
      RUN useradd -s /sbin/nologin -M www
      
      #WORKDIR
      WORKDIR /usr/local/src/nginx-1.14.0
      
      RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.37 && make && make install
      RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
      
      ENV PATH /usr/local/nginx/sbin:$PATH
      EXPOSE 80
      
      CMD ["nginx"]

       

  4. ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.37

    1. --with-http_realip_module #nginx获取客户端真实IP的模块

    2. --with-http_sub_module #用于替换网站页面关键字--平常基本没啥用

    3. --with-http_gzip_static_module #静态缓存压缩,用于减少流量

    4. --with-http_gunzip_module #为不支持gzip模块的客户端提供解压缩服务,用于节省空间减少IO

    5. --with-http_ssl_module #使nginx支持https

    6. --with-http_ssl_module #使nginx支持https

    7. --with-http_stub_status_module #用于监控nginx状态

  5. 生成镜像

    1. docker build -t nginx-file:v1 .

  6. 启动测试

    1. docker -d -p 81:80 --name nginx nginx-file:v1

  7. url访问

    1. localhost:81

转载于:https://my.oschina.net/xpx/blog/1829203

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值