资讯专栏INFORMATION COLUMN

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

Corwien / 2552人阅读

摘要:一测试在官方的基础上简化基础镜像阿里源维护者信息添加扩展这里目标,这里是在运行上面镜像的容器测试得到结果,部分需要自行下载的插件或交互式安装的,使用多带带下载源码编译的方式。

一、测试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的代码。其中在安装memcached(相当于是memcache的新版、强化版)时遇到问题,官方memcached很快安装成功但php扩展难装:多次出现编译错误,php的memcached报缺libmemcached,而后者总是无法通过
参考《错误解决》,使用其中的参考自:https://bugs.launchpad.net/li...

Bug Description
When building with latest GCC version 7
----------

clients/memflush.cc:42:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if (opt_servers == false)
                      ^~~~~
clients/memflush.cc:51:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
     if (opt_servers == false)
                        ^~~~~

Trivial fix:
http://pkgs.fedoraproject.org/cgit/rpms/libmemcached.git/plain/libmemcached-build.patch
#打补丁,兴奋半天没有效果
http://pkgs.fedoraproject.org/cgit/rpms/libmemcached.git/plain/libmemcached-build.patch
patch -p0 < libmemcached-build.patch

最终使用 apk add libmemcached-dev 安装成功!!!(apk add libmemcached,或search的各版本都不行,只要一个dev)

#测试

#swoole 需要对话参数,所以自定义安装
RUN set -ex && 
    mkdir -p ~/build/swoole && 
    cd ~/build/swoole && 
    wget -O swoole.tar.gz https://github.com/swoole/swoole-src/archive/master.tar.gz && 
    tar zxvf swoole.tar.gz --strip-components 1 && 
    /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 set -ex && 
    mkdir -p ~/build/inotify && 
    cd ~/build/inotify && 
    wget -O inotify.tgz https://pecl.php.net/get/inotify-2.0.0.tgz && 
    tar -zxf inotify.tgz --strip-components 1 && 
    /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 set -ex && 
    mkdir -p ~/build/redis && 
    cd ~/build/redis && 
    wget -O redis.tgz https://pecl.php.net/get/redis-4.3.0.tgz && 
    tar -zxf redis.tgz --strip-components 1 && 
    /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 set -ex && 
    mkdir -p ~/build/libuuid && 
    cd ~/build/libuuid && 
    wget -O libuuid.tgz "http://nchc.dl.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz" && 
    tar -zxf libuuid.tgz --strip-components 1 && 
    ./configure --prefix=/usr && 
    make && make install && 
    cd ../ && rm -rf libuuid* && 
    
    wget -O uuid.tgz http://pecl.php.net/get/uuid-1.0.4.tgz && 
    tar zxf uuid.tgz --strip-components 1 && 
    /usr/local/php/bin/phpize && 
    ./configure --with-php-config=/usr/local/php/bin/php-config && 
    make && make install && 
    cd ../ && rm -rf uuid*

#memcached
RUN set -ex && 
    #测试命令:/usr/bin/memcached -d -m 1024 -u root -l 0.0.0.0 -p 11211 -c 1024 -P /tmp/memcached.pid 启动正常
    mkdir -p ~/build/memcached && 
    cd ~/build/memcached && 
    wget -O memcached.tgz "http://memcached.org/files/memcached-1.5.16.tar.gz" && 
    tar -zxf memcached.tgz --strip-components 1 && 
    ./configure --with-event-libevent-dir=/usr --prefix=/usr && 
    make && make install && 
    cd ../ && rm -rf memcached* && 
    
    #需要libmemcached
    apk add libmemcached-dev && 
    
    mkdir -p ~/build/memcached_p && 
    cd ~/build/memcached_p && 
    wget -O memcached.tgz "https://pecl.php.net/get/memcached-3.1.3.tgz" && 
    tar -zxf memcached.tgz --strip-components 1 && 
    /usr/local/php/bin/phpize && 
    ./configure --with-php-config=/usr/local/php/bin/php-config && 
    make && make install && 
    cd ../ && rm -rf memcached_p*

#编译使用,运行时共享 -v /your_real_path/ /usr/local/php/etc/
COPY config /usr/local/php/etc
VOLUME ["/usr/local/php/etc","/var/www/html"]

RUN set -ex 
    && /usr/local/php/bin/pecl channel-update pecl.php.net 
    && /usr/local/php/bin/pecl install igbinary event 
    && /usr/local/php/bin/php -m

3、合并,再添加

CMD ["/usr/local/php/etc/start.sh"]

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/27942.html

相关文章

  • PHP新手开发者的路线建议

    摘要:年开发者应该熟练使用,并且知道版本更新内容。对开发和运维人员来说,最希望的就是一次性创建或配置,可以在任意地方正常运行。是标准规范,是开发的实践标准。对开发者来说语言推荐和,全栈的选择非常多,推荐热门的 前言 在前天(2018-08-02)已经发布了PHP 7.3.0.beta1 Released 如果你还没有使用 PHP7 ,那真的很遗憾。2018年PHP开发者应该熟练使用 PHP7...

    klinson 评论0 收藏0
  • 全栈学习实践)四、docker搭建mysql主从实践

    摘要:上需要主从服务器端配合完成初始化同步用户主服务器端手动同步初始数据添加测试数据,适合从一台拓展至多台服务器的情况。 目前已完成:php7及扩展、redis5的Dockerfile测试版编写,稍许完善后同步上传到github,(记下这里memcached还没有剥离安装)。今天数据库,编程的一个重要原则是不要重复造轮子,php因为需要很多自定义插件、所以单独编译镜像,其实其他包括redis...

    instein 评论0 收藏0
  • 全栈开发自学路线

    摘要:前言这里筑梦师是一名正在努力学习的开发工程师目前致力于全栈方向的学习希望可以和大家一起交流技术共同进步用简书记录下自己的学习历程个人学习方法分享本文目录更新说明目录学习方法学习态度全栈开发学习路线很长知识拓展很长在这里收取很多人的建议以后决 前言 这里筑梦师,是一名正在努力学习的iOS开发工程师,目前致力于全栈方向的学习,希望可以和大家一起交流技术,共同进步,用简书记录下自己的学习历程...

    galaxy_robot 评论0 收藏0

发表评论

0条评论

Corwien

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<