创建LNMP环境的docker镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#基于CentOS6.6的LNMP环境
FROM centos:6.6
MAINTAINER zhouchangju zhouchangju@myhexin.com

#安装基本环境
RUN yum list
RUN yum install -y make cmake gcc gcc-c++ gcc-g77 flex lrzsz bison file libtool libtool-libs autoconf kernel-devel patch wget libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils net-tools libc-client-devel psmisc libXpm-devel git-core c-ares-devel pcre-devel vim mlocate vixie-cron crontabs

#用来保存安装包和安装包解压后的文件
ENV INSTALL_DIR /root/src
RUN mkdir $INSTALL_DIR
RUN groupadd 10jqka >>/dev/null\
&& useradd -s /sbin/nologin -g 10jqka 10jqka >> /dev/null

RUN echo "service rsyslog start" >> /etc/rc.local

########################################---Libmcrypt---#######################################
ADD libmcrypt-2.5.8.tar.gz $INSTALL_DIR/
RUN cd $INSTALL_DIR/libmcrypt-2.5.8\
&& ./configure\
&& make\
&& make install\
&& /sbin/ldconfig\
&& cd libltdl/\
&& ./configure --enable-ltdl-install \
&& make && make install\
&& ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la\
&& ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so\
&& ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4\
&& ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8\
&& ldconfig


########################################---Nginx---#######################################
#将nginx安装包放入image
RUN mkdir -p /usr/local/nginx
#ADD会自动解压(COPY不会自动解压),所以后续就不需要手动tar -xvzf nginx-1.8.0.tar.gz了
ADD nginx-1.8.0.tar.gz $INSTALL_DIR/
RUN cd $INSTALL_DIR/nginx-1.8.0\
&& ./configure --user=10jqka --group=10jqka --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-http_sub_module ${NginxMAOpt}\
&& make && make install\
&& touch /etc/logrotate.d/nginx

ADD nginx.conf /usr/local/nginx/conf/
#加入启动任务
RUN echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local


########################################---PHP---#######################################
RUN mkdir -p /usr/local/php
ADD php-5.6.10.tar.gz $INSTALL_DIR/
RUN cd $INSTALL_DIR/php-5.6.10\
&& ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/lib --enable-fpm --with-fpm-user=10jqka --with-fpm-group=10jqka --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache \
&& make ZEND_EXTRA_LIBS='-liconv'\
&& make install\
&& mkdir -p /usr/local/php/logs

ADD php.ini /usr/local/php/lib/
ADD php-fpm.conf /usr/local/php/etc/

RUN echo "/usr/local/php/sbin/php-fpm" >> /etc/rc.local

#运行容器的SHELL
CMD /bin/bash