zoukankan      html  css  js  c++  java
  • Dockerfile搭建web环境

    基于alpine的web服务环境搭建
    包括:

    • NGINX,HTTPD,LIGHTTPD
    • PYTHON,PHP
      可以根据情况进行删减
    # Dockerfile for Webserver stack
    # Nginx,Lighttpd,Httpd,Python,Php
    
    # Build with:
    # docker build -t name:tag .
    
    # Run with:
    # docker run -it name:tag
    
    # tar with:
    # docker save  name:tag -o name.tar
    
    
    FROM alpine:3.11
    
    LABEL Jmt jmt0826@163.com
    
    ENV TZ "Asia/Shanghai"
    
    
    ###############################################################################
    #                                INSTALLATION
    ###############################################################################
    
    
    ### install prerequisites (gcc, openssl, bzip, pcre, zlib, libxml, curl, png, mcrypt, gosu, libexpat1-dev , libffi-dev for webserver)
    
    
    RUN set -x 
        && echo "http://mirrors.aliyun.com/alpine/v3.9/main/" > /etc/apk/repositories  
        && echo "http://mirrors.aliyun.com/alpine/v3.9/community/" >> /etc/apk/repositories 
        && apk update 
        && apk add --virtual .build-deps --no-cache 
        ca-certificates curl gcc make  pcre-dev openssl-dev zlib-dev g++ expat-dev freetype   libjpeg-turbo-dev freetype-dev bzip2-dev bash libffi-dev libxml2-dev curl-dev libpng-dev libmcrypt-dev perl ;   
        rm -rf /var/cache/apk/* ; 
    
    
    ### set current package version
    
    
    ARG SERVER_VERSION=1.0.0
    
    
    ### install Nginx
    
    
    # predefine env vars, as you can't define an env var that references another one in the same block
    ENV 
        NGINX_HOME=/opt/nginx 
        NGIND_PATH=/usr/local/nginx
    
    ENV 
        NGINX_PACKAGE=nginx-1.18.0.tar.gz 
        NGINX_GID=991 
        NGINX_UID=991 
        NGINX_PATH_CONF=/usr/local/nginx/conf
        
    RUN mkdir ${NGINX_HOME} 
        && curl -O http://mirrors.sohu.com/nginx/${NGINX_PACKAGE} 
        && tar xzf ${NGINX_PACKAGE} -C ${NGINX_HOME} --strip-components=1  
        && rm -f ${NGINX_PACKAGE} 
        && addgroup -S www -g ${NGINX_GID} 
        && adduser -S -s /usr/sbin/nologin -H -g "Nginx service user" -u ${NGINX_UID} -G www www 
        && mkdir -p /usr/local/nginx 
        && cd ${NGINX_HOME}  
        && ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module  
        && make && make install 
    
    
    # ### install apache2
    ENV 
        HTTPD_HOME=/opt/apache2 
        HTTPD_PATH=/usr/local/apache2
    
    ENV 
        HTTPD_PACKAGE=httpd-2.4.43.tar.gz
        APR_PACKAGE=apr-1.7.0.tar.gz 
        APRUTIL_PACKAGE=apr-util-1.6.1.tar.gz
        HTTPD_PATH_CONF=/usr/local/apache2/conf
    
    
    RUN mkdir ${HTTPD_HOME} 
        && curl -O http://mirrors.sohu.com/apache/${HTTPD_PACKAGE} 
        && curl -O https://mirrors.bfsu.edu.cn/apache//apr/${APR_PACKAGE} 
        && curl -O https://mirrors.bfsu.edu.cn/apache//apr/${APRUTIL_PACKAGE} 
        && mkdir -p ${HTTPD_HOME}/srclib/apr ${HTTPD_HOME}/srclib/apr-util 
        && tar xzf ${HTTPD_PACKAGE} -C ${HTTPD_HOME} --strip-components=1 
        && tar xzf ${APR_PACKAGE} -C ${HTTPD_HOME}/srclib/apr --strip-components=1 
        && tar xzf ${APRUTIL_PACKAGE} -C ${HTTPD_HOME}/srclib/apr-util --strip-components=1 
        && rm -f ${HTTPD_PACKAGE} ${APR_PACKAGE} ${APRUTIL_PACKAGE} 
        && cd ${HTTPD_HOME} 
        && ./configure --prefix=/usr/local/apache2 --with-included-apr --with-pcre=/usr/bin/pcre-config --with-devrandom   
        && make && make install 
    
    
    # ## install lighttpd
    ENV 
        LIGHTTPD_HOME=/opt/lighttpd   
        LIGHTTPD_PATH=/usr/local/lighttpd
    
    ENV 
        LIGHTTPD_PACKAGE=lighttpd-1.4.55.tar.gz
        LIGHTTPD_PATH_CONF=/usr/local/lighttpd/config
    
    RUN mkdir ${LIGHTTPD_HOME} 
        && curl -O https://download.lighttpd.net/lighttpd/releases-1.4.x/${LIGHTTPD_PACKAGE} 
        && tar xzf ${LIGHTTPD_PACKAGE} -C ${LIGHTTPD_HOME} --strip-components=1 
        && rm -f ${LIGHTTPD_PACKAGE} 
        && cd ${LIGHTTPD_HOME}  
        && ./configure --prefix=/usr/local/lighttpd 
        && make && make install 
    
    ### install php
    
    ENV 
        PHP_HOME=/opt/php5 
        OPENSSL_HOME=/opt/openssl2
    
    ENV 
        PHP_PACKAGE=php-5.6.33.tar.gz
        OPENSSL_PACKAGE=openssl-1.0.2k.tar.gz
    
    RUN mkdir ${OPENSSL_HOME}
        && curl -O  https://www.openssl.org/source/${OPENSSL_PACKAGE} 
        && tar xzf ${OPENSSL_PACKAGE} -C ${OPENSSL_HOME} --strip-components=1 
        && rm -f ${OPENSSL_PACKAGE} 
        && cd ${OPENSSL_HOME} 
        && ./config 
        && make && make install
    
    RUN mkdir ${PHP_HOME} 
        && curl -O  http://mirrors.sohu.com/php/${PHP_PACKAGE} 
        && tar xzf ${PHP_PACKAGE} -C ${PHP_HOME} --strip-components=1 
        && rm -f ${PHP_PACKAGE} 
        && cd ${PHP_HOME} 
        && ./configure --prefix=/usr/local/php --with-openssl=/usr/local/ssl --enable-fpm --with-curl --enable-ftp --with-gd --enable-mbstring 
        --with-mcrypt --enable-sockets  --enable-ftp --with-gd --enable-mbstring --with-mcrypt --enable-sockets  --enable-zip 
        --with-zlib-dir --with-mhash --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd  --with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd 
        && make && make install 
    
    
    # ### install python
    
    ENV 
        PYTHON_HOME=/opt/python3 
        WSGI_HOME=/opt/wsgi 
        WSGI_PACKAGE=mod_wsgi-4.7.1.tar.gz
    
    ENV 
        PYTHON_PACKAGE=Python-3.7.4.tgz
    
    ADD ./requirements.txt ${PYTHON_HOME}/requirements.txt
    
    RUN curl -O http://mirrors.sohu.com/python/3.7.4/${PYTHON_PACKAGE} 
        && tar xzf ${PYTHON_PACKAGE} -C ${PYTHON_HOME} --strip-components=1 
        && rm -f ${PYTHON_PACKAGE} 
        && cd ${PYTHON_HOME} 
        && ./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC
        && make && make install 
        && cp /usr/local/python3/lib/libpython3.7m.so.1.0  /usr/lib 
        && ln -s /usr/local/python3/bin/python3 /usr/bin/python3 
        && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 
        && pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple  -r ${PYTHON_HOME}/requirements.txt 
        && ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi 
    
    RUN mkdir ${WSGI_HOME}
        && curl -O https://files.pythonhosted.org/packages/74/98/812e68f5a1d51e9fe760c26fa2aef32147262a5985c4317329b6580e1ea9/${WSGI_PACKAGE}
        && tar xzf ${WSGI_PACKAGE} -C ${WSGI_HOME} --strip-components=1 
        && cd ${WSGI_HOME}  
        && sed -i "1c #!/usr/bin/perl -w" /usr/local/apache2/bin/apxs 
        && ./configure --with-apxs=/usr/local/apache2/bin/apxs  --with-python=/usr/local/python3/bin/python3.7  
        && make && make install  
        && chmod 755 /usr/local/apache2/modules/mod_wsgi.so
    
    
    # ##############################################################################
    # #                             START-UP SCRIPTS
    # ##############################################################################
    
    # ## SERVER  SCRIPTS
    RUN mv ${NGIND_PATH}/html  ${NGIND_PATH}/www 
        && mv ${HTTPD_PATH}/htdocs ${HTTPD_PATH}/www 
        && mkdir -p ${LIGHTTPD_PATH}/www ${LIGHTTPD_PATH}/log ${LIGHTTPD_PATH}/run 
        && chown -R www:www ${LIGHTTPD_PATH} 
        && rm -rf /opt/*
    
    
    
    ###############################################################################
    #                                   START
    ###############################################################################
    
    ADD ./php/lib  /usr/local/php/lib
    ADD ./php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf
    
    ADD ./start.sh /usr/local/bin/start.sh
    RUN chmod +x /usr/local/bin/start.sh
    
    EXPOSE 80
    CMD [ "/usr/local/bin/start.sh" ]
    
    
  • 相关阅读:
    Linux命令之 文件归档管理
    C#总结项目《影院售票系统》编写总结完结篇
    C#总结项目《影院售票系统》编写总结三
    C#中MD5加密
    C#中的序列化与反序列化
    C#总结项目《影院售票系统》编写总结二
    C#总结项目《影院售票系统》编写总结一
    java多线程与线程并发四:线程范围内的共享数据
    java多线程与线程并发三:线程同步通信
    java多线程与线程并发二:线程互斥
  • 原文地址:https://www.cnblogs.com/jmtang/p/14178051.html
Copyright © 2011-2022 走看看