(全栈学习实践)三、创建php、添加扩展,其他Dockerfile编写

栏目: PHP · 发布时间: 4年前

内容简介:一、测试PHP1、在官方的基础上简化:2、添加扩展:

一、测试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"]

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C#本质论

C#本质论

米凯利斯 / 周靖 / 人民邮电出版社 / 2010-9 / 99.00元

《C#本质论(第3版)》是一部好评如潮的语言参考书,作者用一种非常合理的方式来组织《C#本质论(第3版)》的内容,由浅人深地介绍了C#语言的各个方面。全书共包括21章及6个附录,每章开头的“思维导图”指明了本章要讨论的主题,以及各个主题之间的层次关系。书中所包含的丰富的示例代码和精要的语言比较,都有助于读者理解C#语言。《C#本质论(第3版)》首先介绍了C#语言的基础知识,随后深人讲解了泛型、迭代......一起来看看 《C#本质论》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具