##docker-compose 创建nginx+php
mkdir -p composetest/nignx cd composetest ########## vim nginx/Dockerfile ################# FROM centos:6.8 WORKDIR /usr/src RUN yum install -y zlib-devel gd-devel pcre-devel pcre openssl-devel lua lua-devel gcc gcc-c++ wget RUN wget -q http://indoor.meilele.com/download/centos/nginx-1.0.8.tar.gz RUN wget -q http://indoor.meilele.com/download/centos/ngx_open.tar.gz RUN tar zxf ngx_open.tar.gz -C /usr/src/ RUN tar zxf nginx-1.0.8.tar.gz -C /usr/src/ WORKDIR /usr/src/nginx-1.0.8 RUN useradd -M -s /sbin/nologin nginx RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --add-module=/usr/src/ngx_openresty/ngx_devel_kit --add-module=/usr/src/ngx_openresty/array-var-nginx-module --add-module=/usr/src/ngx_openresty/headers-more-nginx-module --add-module=/usr/src/ngx_openresty/rds-csv-nginx-module --add-module=/usr/src/ngx_openresty/auth-request-nginx-module --add-module=/usr/src/ngx_openresty/iconv-nginx-module --add-module=/usr/src/ngx_openresty/memc-nginx-module --add-module=/usr/src/ngx_openresty/rds-json-nginx-module --add-module=/usr/src/ngx_openresty/redis2-nginx-module --add-module=/usr/src/ngx_openresty/set-misc-nginx-module --add-module=/usr/src/ngx_openresty/echo-nginx-module --add-module=/usr/src/ngx_openresty/srcache-nginx-module --add-module=/usr/src/ngx_openresty/encrypted-session-nginx-module --add-module=/usr/src/ngx_openresty/form-input-nginx-module --add-module=/usr/src/ngx_openresty/xss-nginx-module --add-module=/usr/src/ngx_openresty/ngx_lua/ --with-http_ssl_module --add-module=/usr/src/ngx_openresty/ipseek --with-http_image_filter_module && make && make install RUN wget http://indoor.meilele.com/download/centos/script/install/ngservice.sh -O /etc/init.d/nginx RUN chmod 755 /etc/init.d/nginx RUN chkconfig --add nginx RUN egrep -v '#|^$' /usr/local/nginx/conf/nginx.conf.default >/usr/local/nginx/conf/nginx.conf RUN mkdir -p /data/html RUN mkdir -p /usr/local/nginx/conf/conf.d && sed -i '/server {/ i include conf/conf.d\/\*.conf;' /usr/local/nginx/conf/nginx.conf RUN sed -i '/location \/ {/ i location ~ \.php(.*)$ {\nfastcgi_pass 127.0.0.1:9000;\nfastcgi_index index.php;\nfastcgi_split_path_info ^((?U).+\.php)(/?.+)$;\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\nfastcgi_param PATH_INFO $fastcgi_path_info;\nfastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;\ninclude fastcgi_params;\n}' /usr/local/nginx/conf/nginx.conf RUN sed -i 's/index index.html index.htm.*/index index.html index.htm index.php;/g' /usr/local/nginx/conf/nginx.conf RUN echo "" >/usr/local/nginx/html/index.php ###########install php5.6.0 RUN yum install -y epel-release RUN yum install -y gd-devel pcre-devel pcre lua lua-devel gcc gcc-c++ wget libxml2 libxml2-devel curl-devel curl openldap openldap-clients openldap-devel openldap-servers patch bzip2 openssl openssl-devel bzip2-devel libxslt libxslt-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel libmcrypt-devel mcrypt tree RUN [ $(grep -c 'include /usr/local/lib/*.conf' /etc/ld.so.conf) -eq 0 ] && echo 'include /usr/local/lib/*.conf' >>/etc/ld.so.conf && ldconfig RUN cp -frp /usr/lib64/libldap* /usr/lib/ #RUN useradd -M -s /sbin/nologin php ##--with-fpm-user=php --with-fpm-group=php #RUN wget -q http://cn2.php.net/distributions/php-5.6.0.tar.gz RUN wget -q http://indoor.meilele.com/download/centos/php-5.6.0.tar.gz RUN wget -q http://pecl.php.net/get/memcache-2.2.7.tgz RUN wget -q https://jaist.dl.sourceforge.net/project/php-screw/php-screw/1.5/php_screw-1.5.tar.gz --no-check-certificate RUN wget -q https://github.com/alanxz/rabbitmq-c/releases/download/v0.7.1/rabbitmq-c-0.7.1.tar.gz --no-check-certificate RUN wget -q https://pecl.php.net/get/amqp-1.6.1.tgz --no-check-certificate RUN wget -q http://indoor.meilele.com/download/centos/ImageMagick-6.9.8-10.tar.gz RUN wget -q http://pecl.php.net/get/imagick-3.1.0.tgz RUN wget -q http://pecl.php.net/get/xhprof-0.9.4.tgz RUN tar zxf php-5.6.0.tar.gz -C /usr/src/ RUN tar zxf memcache-2.2.7.tgz -C /usr/src/ RUN tar zxf php_screw-1.5.tar.gz -C /usr/src/ RUN tar zxf rabbitmq-c-0.7.1.tar.gz -C /usr/src/ RUN tar zxf amqp-1.6.1.tgz -C /usr/src/ RUN tar zxf ImageMagick-6.9.8-10.tar.gz -C /usr/src/ RUN tar zxf imagick-3.1.0.tgz -C /usr/src/ RUN tar zxf xhprof-0.9.4.tgz -C /usr/src/ RUN cd /usr/src/php-5.6.0 && ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --enable-fpm --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-png-dir --with-jpeg-dir --with-freetype-dir --enable-mbstring --enable-session --enable-ftp --enable-calendar && make && make install && \cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod 755 /etc/init.d/php-fpm && egrep '^[a-zA-Z[]' /usr/local/php/etc/php-fpm.conf.default >/usr/local/php/etc/php-fpm.conf && grep '^[a-zA-Z[]' php.ini-production >/usr/local/php/etc/php.ini && cd ext/mbstring && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install RUN cd /usr/src/memcache-2.2.7 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install RUN [ $(grep -c 'extension=memcache.so' /usr/local/php/etc/php.ini) -eq 0 ] && echo ' extension=memcache.so' >>/usr/local/php/etc/php.ini RUN cd /usr/src/php_screw-1.5 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make || (cp -frp php_screw.c php_screw.c.bak; sed -i 's#CG(extended_info) = 1;#CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;#g' php_screw.c ;make ) && make install RUN [ $(grep -c 'extension=php_screw.so' /usr/local/php/etc/php.ini) -eq 0 ] && echo ' extension= php_screw.so' >>/usr/local/php/etc/php.ini RUN cd /usr/src/rabbitmq-c-0.7.1 && ./configure --prefix=/usr/local/rabbitmq-c-0.7.1 && make && make install RUN cd /usr/src/amqp-1.6.1 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.7.1 && make && make install ENV CPPFLAGS -Ic:/Progra~1/GnuWin32/include ENV LDFLAGS -Lc:/Progra~1/GnuWin32/lib RUN cd /usr/src/ImageMagick-6.9.8-10 && ./configure --without-perl && make && make install && ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick RUN cd /usr/src/imagick-3.1.0 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install RUN [ $(grep -c 'extension=imagick.so' /usr/local/php/etc/php.ini) -eq 0 ] && echo 'extension = imagick.so' >>/usr/local/php/etc/php.ini RUN cd /usr/src/xhprof-0.9.4 && cd extension/ ;/usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xhprof && make && make install RUN [ $(grep -c 'extension=xhprof.so' /usr/local/php/etc/php.ini) -eq 0 ] && (mkdir -p /data/www/xhprof/output ;echo -e "[xhprof]\nextension=xhprof.so\nxhprof.output_dir=/data/www/xhprof/output" >>/usr/local/php/etc/php.ini) EXPOSE 80 443 CMD /etc/init.d/php-fpm start && /usr/local/nginx/sbin/nginx -g "daemon off;" ######################## cat >docker-compose.yml <<EOF version: "3" services: nginx: build: nginx/ ports: - "80:80" - "443:443" volumes: - /data/nginx/conf.d:/usr/local/nginx/conf/conf.d - /data/nginx/html:/data/html EOF ########################## docker-compose -f docker-compose.yml up -d