设为首页 收藏本站
查看: 1623|回复: 0

[经验分享] dockerfile自动部署openresty+php7

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-2 09:13:28 | 显示全部楼层 |阅读模式
FROM centos:7
MAINTAINER Carl <lpl20150013@163.com>


#====================================解决依赖关系============================================

ENV NGINX_VERSION 1.10.2
ENV PHP_VERSION 7.0.12
ENV LIBICONV_VERSION 1.14

RUN yum -y install bzip* libm* mhash* \
    ImageMagick* php-pear* php-devel* \
    autoconf automake openssh  libiconv* \
    libreoffice-headless  libreoffice-writer lua* \
    libtool cmake make --skip-broken  && \
    yum clean all

#=============================================================================================
#
RUN rpm -ivh http://dl.fedoraproject.org/pub/ ... ease-7-8.noarch.rpm && \
    yum install -y wget \
    wget zlib-devel zlib* \
    python-setuptools openssh* libmcrypt* \
    freetype-devel libpng-devel libjpeg-devel \
    pcre-devel lrzsz* gcc* image* openoffice* \
    libxslt-devel   freetype-devel  libpng-devel   \
    libcurl-devel openldap* postgresql-devel \
    curl-devel bzip2-devel  libjpeg-devel  readline-devel \
    libmcrypt* glibc* libcurl* \
    screen tree lsof htop iptraf  sysstat inotify-tools  htop\
    mcrypt* libevent* libxml2* \
    post* pcre* gcc-c++ && \
    yum clean all

#====================================安装nginx && php7=========================================
RUN groupadd -r www && \
    useradd -M -s /sbin/nologin -r -g www www


#download nginx libiconv and php7,libiconv1.14版本存在BUG
RUN mkdir -p /usr/local/src/nginx-php && cd $_ && \
    wget -c -O nginx.tar.gz http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz && \
    wget -O php.tar.gz http://php.net/distributions/php-$PHP_VERSION.tar.gz && \
    wget -c -O libiconv.tar.gz http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz && \
    curl -O -SL https://github.com/xdebug/xdebug/archive/XDEBUG_2_4_0RC3.tar.gz


#Make install nginx
RUN cd  /usr/local/src/nginx-php && \
    tar -zxvf nginx.tar.gz && \
    cd nginx-$NGINX_VERSION && \
        ./configure --prefix=/usr/local/nginx \
        --user=www --group=www \
        --error-log-path=/var/log/nginx_error.log \
        --http-log-path=/var/log/nginx_access.log \
        --pid-path=/var/run/nginx.pid \
        --with-pcre \
        --with-http_ssl_module \
        --without-mail_pop3_module \
        --without-mail_imap_module \
        --with-http_gzip_static_module && \
        make && make install

#Make install libiconv,存在BUG可修复
#stdio.in.h找到
#_GL_WARN_ON_USE (gets,"gets is a security hole - use fgets instead");
#注释掉
#添加
##ifdefined(__GLIBC__)&&!defined(__UCLIBC__)&&!__GLIBC_PREREQ(2,16)
# _GL_WARN_ON_USE (gets,"gets is a security hole - use fgets instead");
##endif
RUN cd  /usr/local/src/nginx-php && \
    tar -zxvf libiconv.tar.gz && \
    cd libiconv-$LIBICONV_VERSION && \
    ./configure --prefix=/usr/local/libiconv && \
    make -j 4 && make install


#Make install php7
RUN cd  /usr/local/src/nginx-php && \
        tar -zvxf php.tar.gz && \
    cd php-$PHP_VERSION && \
        ./configure --prefix=/usr/local/php \
        --with-config-file-path=/usr/local/php/etc \
        --with-config-file-scan-dir=/usr/local/php/etc/php.d \
        --with-fpm-user=www \
        --with-fpm-group=www \
        --with-mcrypt=/usr/include \
    --with-iconv=/usr/local/libiconv \
        --with-mysqli \
        --with-pdo-mysql \
        --with-openssl \
        --with-gd \
        --with-zlib \
        --with-gettext \
        --with-curl \
        --with-png-dir \
        --with-jpeg-dir \
    --with-freetype-dir \
        --with-xmlrpc \
        --with-mhash \
    --with-openssl \
        --enable-fpm \
        --enable-xml \
        --enable-shmop \
        --enable-sysvsem \
        --enable-inline-optimization \
        --enable-mbregex \
        --enable-mbstring \
        --enable-ftp \
        --enable-gd-native-ttf \
        --enable-mysqlnd \
        --enable-pcntl \
        --enable-sockets \
        --enable-zip \
        --enable-soap \
        --enable-session \
        --enable-opcache \
        --enable-bcmath \
        --enable-exif \
        --enable-fileinfo \
        --disable-rpath \
        --disable-debug \
        --without-pear && \
        make -j 4 && make install


#=======================================================================================================
#
#Add xdebug extension
RUN cd /home/nginx-php && \
    tar -zxvf XDEBUG_2_4_0RC3.tar.gz && \
    cd xdebug-XDEBUG_2_4_0RC3 && \
    /usr/local/php/bin/phpize && \
    ./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config && \
    make && \
    cp modules/xdebug.so /usr/local/php/lib/php/extensions/xdebug.so

RUN     cd /home/nginx-php/php-$PHP_VERSION && \
    cp php.ini-production /usr/local/php/etc/php.ini && \
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && \
    cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#
#=======================================================================================================
#Install supervisor
RUN easy_install supervisor && \
    mkdir -p /var/log/supervisor && \
    mkdir -p /var/run/sshd && \
    mkdir -p /var/run/supervisord

#Add supervisord conf
ADD supervisord.conf /etc/supervisord.conf

#Create web folder
VOLUME ["/data/www", "/usr/local/nginx/conf/ssl", "/usr/local/nginx/conf/vhost", "/usr/local/php/etc/php.d"]
ADD index.php /data/www/index.php

ADD xdebug.ini /usr/local/php/etc/php.d/xdebug.ini

#Update nginx config
ADD nginx.conf /usr/local/nginx/conf/nginx.conf

#========================向容器中添加文件===============================
#Start
ADD start.sh /start.sh
RUN chmod +x /start.sh

#======================指定容器映射到主机的端口=========================
#Set port
EXPOSE 8080 443 9000

#========================================================
#Start it
ENTRYPOINT ["/start.sh"]

   
#!/bin/sh
#########################################################################
# File Name: start.sh
# Author: TiMOphY
#########################################################################
Nginx_Install_Dir=/usr/local/nginx
DATA_DIR=/data/www

set -e

chown -R www.www $DATA_DIR

if [[ -n "$PROXY_WEB" ]]; then

    [ -f "${Nginx_Install_Dir}/conf/ssl" ] || mkdir -p $Nginx_Install_Dir/conf/ssl
    [ -f "${Nginx_Install_Dir}/conf/vhost" ] || mkdir -p $Nginx_Install_Dir/conf/vhost

    if [ -z "$PROXY_DOMAIN" ]; then
            echo >&2 'error:  missing PROXY_DOMAIN'
            echo >&2 '  Did you forget to add -e PROXY_DOMAIN=... ?'
            exit 1
    fi

    if [ -z "$PROXY_CRT" ]; then
         echo >&2 'error:  missing PROXY_CRT'
         echo >&2 '  Did you forget to add -e PROXY_CRT=... ?'
         exit 1
     fi

     if [ -z "$PROXY_KEY" ]; then
             echo >&2 'error:  missing PROXY_KEY'
             echo >&2 '  Did you forget to add -e PROXY_KEY=... ?'
             exit 1
     fi

     if [ ! -f "${Nginx_Install_Dir}/conf/ssl/${PROXY_CRT}" ]; then
             echo >&2 'error:  missing PROXY_CRT'
             echo >&2 "  You need to put ${PROXY_CRT} in ssl directory"
             exit 1
     fi

     if [ ! -f "${Nginx_Install_Dir}/conf/ssl/${PROXY_KEY}" ]; then
             echo >&2 'error:  missing PROXY_CSR'
             echo >&2 "  You need to put ${PROXY_KEY} in ssl directory"
             exit 1
     fi

    cat > ${Nginx_Install_Dir}/conf/vhost/website.conf << EOF
server {
    listen 80;
    server_name $PROXY_DOMAIN;
    return 301 https://$PROXY_DOMAIN\$request_uri;
    }

server {
    listen 443 ssl;
    server_name $PROXY_DOMAIN;

    ssl on;
    ssl_certificate ssl/${PROXY_CRT};
    ssl_certificate_key ssl/${PROXY_KEY};
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    keepalive_timeout 70;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;

    root   $DATA_DIR;
    index  index.php index.html index.htm;

    location / {
        try_files \$uri \$uri/ /index.php?\$args;
    }

    location ~ \.php$ {
        root           /data/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /\$document_root\$fastcgi_script_name;
        include        fastcgi_params;
    }
}
EOF
fi

/usr/bin/supervisord -n -c /etc/supervisord.conf




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-294576-1-1.html 上篇帖子: linux 安装redmine文档 下篇帖子: docker-4 Dockerfile的使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表