dockerfile php5.6+nginx+swoole
# .::::.
# .::::::::.
# :::::::::::
# ..:::::::::::'
# '::::::::::::'
# .::::::::::
# '::::::::::::::..
# ..::::::::::::.
# ``::::::::::::::::
# ::::``:::::::::' .:::.
# ::::' ':::::' .::::::::.
# .::::' :::: .:::::::'::::.
# .:::' ::::: .:::::::::' ':::::.
# .::' :::::.:::::::::' ':::::.
# .::' ::::::::::::::' ``::::.
# ...::: ::::::::::::' ``::.
# ```` ':. ':::::::::' ::::..
# '.:::::' ':'````..
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# 美女鎮樓 永無BUG
#################################################
# Dockerfile to build lnmp_swoole container
# php5.6 nginx
# base on centos 7.5
#################################################
# set the base image to centos
FROM centos:7.5.1804
# file Author/Maintainer
MAINTAINER ijijni [email protected]
# mkdir /data/software /usr/local/webserver
RUN mkdir -p /data/software && mkdir -p /usr/local/webserver
WORKDIR /data/software
# install extension and install php7.2
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 && \
yum makecache && \
yum -y install gcc gcc-c++ \
autoconf wget \
psmisc \
openssl openssl-devel \
gperftools-devel \
tar \
passwd \
openssh-server \
openssh-clients \
initscripts \
bison bison-dev \
libxslt libxslt-devel \
readline readline-devel \
libmcrypt libmcrypt-devel \
libcurl libcurl-devel \
unzip pcre pcre-devel zlib zlib-devel git \
libxml2 libxml2-devel curl curl-devel \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel \
python-setuptools dos2unix gperf \
libevent libevent-devel bzip2 bzip2-devel ncurses-devel \
boost libtool boost-devel* libuuid-devel python-sphinx.noarch && \
yum clean all && \
rm -rf /var/cache/yum
# install re2c
RUN wget https://sourceforge.net/projects/re2c/files/0.16/re2c-0.16.tar.gz && \
tar zxf re2c-0.16.tar.gz && cd re2c-0.16 && \
./configure && \
make && make install && \
cd .. && rm -rf /data/software/re2c-0.16 /data/software/re2c-0.16.tar.gz
# linux user account set
RUN echo 'root:123465' | chpasswd
RUN /usr/sbin/sshd-keygen
RUN /usr/sbin/groupadd www &&/usr/sbin/useradd -r -m -s /bin/bash -g www www && \
echo "www ALL=(ALL) ALL" >> /etc/sudoers && echo 'root:123465' | chpasswd
# build PHP7.2
RUN wget http://am1.php.net/distributions/php-5.6.37.tar.gz && \
tar zxvf php-5.6.37.tar.gz && rm -f php-5.6.37.tar.gz && \
cd php-5.6.37 && \
./configure \
--prefix=/usr/local/webserver/php \
--with-config-file-path=/usr/local/webserver/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache && \
make clean &&make && make install && \
cp ./php.ini-development /usr/local/webserver/php/etc/php.ini && \
# build systemd and deletes a number of unit files which might cause issues
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*; \
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*; \
rm -f /lib/systemd/system/anaconda.target.wants/*; \
# config
cd /data/software && rm -rf php-5.6.37 && \
mv /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf && \
ln -s /usr/local/webserver/php/bin/php /usr/local/bin/php && \
#build systemd php-fpm
echo -e " [Unit] \n \
Description=php-fpm \n \
After=network.target \n \
[Service] \n \
Type=forking \n \
ExecStart=/usr/local/webserver/php/sbin/php-fpm \n \
ExecStop=/bin/pkill -9 php-fpm \n \
PrivateTmp=true \n \
[Install] \n \
WantedBy=multi-user.target" > /usr/lib/systemd/system/php-fpm.service && \
systemctl enable php-fpm.service
#build php redis mongodb extension
RUN /usr/local/webserver/php/bin/pecl install redis && \
sed -i '$a extension=redis.so\n' /usr/local/webserver/php/etc/php.ini
#安裝 PHP的mongodb擴充套件
RUN /usr/local/webserver/php/bin/pecl install mongodb && \
sed -i '$a extension=mongodb.so\n' /usr/local/webserver/php/etc/php.ini
#build swoole
RUN wget https://github.com/nghttp2/nghttp2/releases/download/v1.32.1/nghttp2-1.32.1.tar.gz && \
tar zxvf nghttp2-1.32.1.tar.gz && cd nghttp2-1.32.1 && ./configure && make clean && make && make install && \
cd .. && rm -rf nghttp2-1.32.1.tar.gz && rm -rf nghttp2-1.32.1 && \
wget https://codeload.github.com/redis/hiredis/tar.gz/v0.13.3 && \
tar zxvf v0.13.3 && cd hiredis-0.13.3 && make clean && make && make install && \
mkdir /usr/lib/hiredis && \
# 將動態連線庫libhiredis.so至/usr/lib/hiredis
cp libhiredis.so /usr/lib/hiredis && \
mkdir /usr/include/hiredis && \
cp hiredis.h /usr/include/hiredis && \
echo '/usr/local/lib' >>/etc/ld.so.conf && \
ldconfig && \
cd .. && rm -rf v0.13.3 && rm -rf /data/software/hiredis-0.13.3 && \
wget http://pecl.php.net/get/swoole-1.10.5.tgz && \
tar zxvf swoole-1.10.5.tgz && rm -f swoole-1.10.5.tgz && \
cd swoole-1.10.5 && \
/usr/local/webserver/php/bin/phpize && \
./configure \
--with-php-config=/usr/local/webserver/php/bin/php-config \
--enable-openssl \
--enable-http2 \
--enable-async-redis \
--enable-sockets \
--enable-mysqlnd && \
make clean && make && make install && \
sed -i '$a extension=swoole.so\n' /usr/local/webserver/php/etc/php.ini && cd .. &&rm -rf swoole-1.10.5 && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && chmod +x /usr/local/bin/composer
#build nginx
RUN rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm && \
yum install -y nginx && systemctl enable nginx.service && \
echo -e " #! /bin/bash \n \
source /etc/profile \n " > /run.sh && \
chmod +x /run.sh
# expose
EXPOSE 22 80
# cmd
CMD ["/usr/sbin/init"]