一、测试PHP
1、在官方的基础上简化:
# php7.3.5; Feb 7, 2019 link: https://github.com/docker-library/php/blob/master/7.3/alpine3.9/fpm/Dockerfile
# Base images 基础镜像+阿里源
FROM alpine:3.9
#MAINTAINER 维护者信息
MAINTAINER cffycls@foxmail.com
# dependencies required for running "phpize"
ENV PHP_VERSION 7.3.6
ENV PHP_URL https://secure.php.net/get/php-$PHP_VERSION.tar.xz/from/this/mirror
ENV PHPIZE_DEPS \
autoconf \
dpkg-dev dpkg \
file \
g++ \
gcc \
libc-dev \
make \
pkgconf \
re2c
ENV PHPIZE_DEVS \
argon2-dev \
coreutils \
curl-dev \
libedit-dev \
libsodium-dev \
libxml2-dev \
openssl-dev \
sqlite-dev \
libjpeg-turbo-dev \
libpng-dev \
gd-dev \
gettext-dev \
freetype-dev \
libxpm-dev \
libevent-dev
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update \
&& addgroup -g 82 -S www-data \
&& adduser -u 82 -D -S -G www-data www-data \
&& mkdir -p "/usr/local/etc/php/conf.d" && mkdir -p "/var/www/html" \
&& chown www-data:www-data /var/www/html && chmod 777 /var/www/html \
&& apk add --no-cache\
curl \
tar \
xz \
openssl \
wget
COPY php.tar.xz php.tar.xz
RUN set -eux; \
apk add $PHPIZE_DEPS $PHPIZE_DEVS \
# && wget -O php.tar.xz "$PHP_URL" \
&& tar -Jxf php.tar.xz && 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/conf.d" \
\
--enable-option-checking=fatal \
--with-mhash \
\
--enable-ftp \
--enable-exif \
--enable-mbregex \
--enable-mbstring \
--enable-mysqlnd \
--enable-sysvmsg \
--enable-opcache \
--enable-pcntl \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--with-curl \
--with-libedit \
--with-openssl \
--with-zlib \
--with-pcre-regex \
--with-pear \
--with-libxml-dir=/usr \
--with-jpeg-dir \
--with-freetype-dir \
--with-xpm-dir \
--with-png-dir \
--with-gettext \
--with-mhash \
--with-iconv \
--disable-fileinfo \
\
--enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --disable-cgi \
&& make -j "$(nproc)" \
&& find -type f -name '*.a' -delete \
&& make install \
# && make clean \
&& rm -rf /tmp/pear ~/.pearrc \
&& cd ../ && rm -rf php-$PHP_VERSION.tar.xz php-$PHP_VERSION
2、添加扩展:
这里目标 swoole-inotify-redis-uuid-memcached,这里是在运行上面镜像的容器测试得到结果,部分需要自行下载的插件或交互式安装的,使用单独下载源码编译的方式。/usr/local/php/etc/文件夹需要准备一个共享,这里取上面官方的配置稍加修改,并共享出来供后续安装使用:
[]:~/tmp/dk# tree -a php
php
├── config
│ ├── pear.conf
│ ├── php-fpm.conf
│ ├── php-fpm.conf.default
│ ├── php-fpm.d
│ │ ├── www.conf
│ │ └── www.conf.default
│ ├── php.ini
│ └── start.sh
├── Dockerfile
└── php.tar.xz
测试shell到Dockerfile的代码
#测试
#swoole 需要对话参数,所以自定义安装
RUN -ex && \
mkdir -p ~/build && \
cd ~/build && \
rm -rf ./swoole-src && \
mkdir tmp && \
wget -O ./tmp/swoole.tar.gz https://github.com/swoole/swoole-src/archive/master.tar.gz && \
tar zxvf ./tmp/swoole.tar.gz && \
mv swoole-src* swoole-src && \
cd swoole-src && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config \
--enable-coroutine \
--enable-openssl \
--enable-http2 \
--enable-async-redis \
--enable-sockets \
--enable-mysqlnd && \
make && make install && \
cd .. && rm -rf swoole*
#inotify
RUN -ex && \
wget https://pecl.php.net/get/inotify-2.0.0.tgz && \
tar -zxf inotify-2.0.0.tgz && \
cd inotify-2.0.0 && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config --enable-inotify && \
make && make install && \
cd .. && rm -rf inotify*
#redis
RUN -ex && \
wget -O redis-4.3.0.tgz https://pecl.php.net/get/redis-4.3.0.tgz && \
tar -zxf redis-4.3.0.tgz && \
cd redis-4.3.0 && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config --enable-redis && \
make && make install && \
cd .. && rm -rf redis*
#uuid
RUN -ex && \
wget "http://nchc.dl.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz" && \
tar -zxf libuuid-1.0.3.tar.gz && \
cd libuuid-1.0.3 && \
./configure --prefix=/usr && \
make && make install && \
cd ../ && rm -rf libuuid* && \
\
wget http://pecl.php.net/get/uuid-1.0.4.tgz && \
tar zxf uuid-1.0.4.tgz && \
cd uuid-1.0.4 && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config && \
make && make install && \
cd ../ && rm -rf uuid*
#编译使用,运行时共享 -v /your_real_path/ /usr/local/php/etc/
COPY config /usr/local/php/etc
VOLUME ["/usr/local/php/etc","/var/www/html"]
RUN -ex \
&& apk add libmemcached && /usr/local/php/bin/pecl channel-update pecl.php.net \
&& /usr/local/php/bin/pecl install igbinary event memcached \
&& rm -rf /tmp/pear ~/.pearrc ~/build \
&& apk del $PHPIZE_DEPS $PHPIZE_DEVS \
&& /usr/local/php/bin/php -m
3、合并,再添加
CMD ["/usr/local/php/etc/start.sh"]
发表回复