构建包含phalcon扩展的php镜像

准备

1、下载phalcon 下载地址
2、Dockerfile和phalcon在同一个目录

wangqi@wangqideMac-mini-2  ~/docker  ll
total 18592
-rw-r--r--   1 wangqi  staff   1.6K  6 28 21:33 Dockerfile
-rw-r--r--@  1 wangqi  staff   1.8M  6 28 20:35 cphalcon-3.4.4.tar.gz

3、docker build -t phalcon:v1 .
4、构建过程中有时会因为pecl扩展下载不下来导致构建失败,取消pecl下载,构建完成后进入容器手动安装。

Dockerfile

FROM daocloud.io/php:7.2-fpm-alpine

LABEL maintainer="hiwangqi"

# 修改镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

# 安装依赖,核心扩展,pecl扩展,git,composer,npm工具
RUN apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        curl-dev \
        libtool \
        libxml2-dev \
        postgresql-dev \
		  libmcrypt-dev \
        freetype-dev \
        libjpeg-turbo-dev \
        libpng-dev \
        git \
        imagemagick \
        zlib \
    && pecl install mcrypt-1.0.1 \
    && docker-php-ext-install \
        bcmath \
        pdo_mysql \
        pcntl \
        sockets \
        zip \
        pcntl \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && pecl install -o -f redis \
    && rm -rf /tmp/pear \
    && docker-php-ext-enable redis

WORKDIR /usr/local/etc/php
RUN cp php.ini-production php.ini

# phalcon扩展
WORKDIR /usr/src/php/ext/
COPY cphalcon-3.4.4.tar.gz  /usr/src/php/ext/

RUN set -xe && \
        tar xf cphalcon-3.4.4.tar.gz && cd cphalcon-3.4.4/build && ./install && \
        echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini && \
        rm -rf /usr/src/php/ext/cphalcon-3.4.4.tar.gz cphalcon-3.4.4
   
# composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/bin/composer \
    && composer self-update --clean-backups    

# use aliyun composer
RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 对其他容器开放9000端口
EXPOSE 9000