zoukankan      html  css  js  c++  java
  • dockerfile构架镜像(8)

    nginx镜像的构建

    先查看下本地的镜像,选取官网的centos作为base image:

    [root@server ~]# docker images

    创建一个目录专门用来存放的目录,也就是Dockerfile所在的目录

    [root@server ~]# mkdir myNginx
    [root@server ~]# cd myNginx/
    [root@server myNginx]# touch Dockerfile

    编写Dockerfile文件的内容,注意该文件名字的首字母要大写。

    [root@server myNginx]# cat Dockerfile
    # 指定基础镜像
    FROM centos
    
    # MAINTAINER
    MAINTAINER xxx@qq.com
    
    # 安装基础工具包
    RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
    
    # 下载nginx
    ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
    
    # 解压nginx 并创建用户
    RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ 
        && useradd -M -s /sbin/nologin nginx
    
    # 更改工作目录
    WORKDIR /usr/local/src/nginx-1.12.2
    
    # 编译安装nginx
    RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
    
    # 删除多余安装包 
    RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
    
    # 设置环境变量
    ENV PATH=/usr/local/nginx/sbin:$PATH
    
    # 设置端口
    EXPOSE 80
    View Code

    执行docker build 进行构建:

    [root@server myNginx]# docker build -t centos_nginx:v1 .

    构建成功后,查看新构建的镜像:

    [root@server myNginx]# docker images

    使用v1版本的镜像启动一个容器:

    [root@server myNginx]# docker run -d -p 80:80 centos_nginx:v1 nginx -g "daemon off;"

    查看容器运行状态:

    [root@server myNginx]# docker ps 

    这次构建完成了一个简单的实例。

  • 相关阅读:
    使用XStream解析xml
    分享功能
    上拉加载 下拉刷新
    点击button倒计时
    正则表达式验证手机号码
    第三方登陆
    test
    横向滑动菜单HorizontalScrollView
    slidingmenu侧滑侧单
    2017/4/25 afternoon
  • 原文地址:https://www.cnblogs.com/topass123/p/12613097.html
Copyright © 2011-2022 走看看