问题

准备通过Dockerfile构建php镜像,在使用docker-php-ext-install安装mcrypt扩展时遇到如下错误:

error: /usr/src/php/ext/mcrypt does not exist

原因

mycrypt extension is not provided with the PHP source since 7.2 , but are instead available through PECL. To install a PECL extension in docker, use pecl install to download and compile it, then use docker-php-ext-enable to enable it:

php从7.2开始不再在源码里支持mcrypt扩展而转到pecl方式支持

pecl install mcrypt-1.0.1
docker-php-ext-enable mcrypt

解决

版本切换到7.1再执行构建时问题没有复现,同时按照

pecl install mcrypt-1.0.1
docker-php-ext-enable mcrypt

的方式安装之后也没有出现上述问题

问题

安装过程中提示(虽然不会影响最终结果)

WARNING: Ignoring APKINDEX.e3d33561.tar.gz: No such file or directory

解决

doing apk update fixes the problem (updates the index).

Request: Improve the error message.

Dockerfile(php7.2)

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

LABEL maintainer="[email protected]"

COPY composer.phar /usr/local/bin/

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

# 安装依赖,核心扩展,pecl扩展,git,composer,npm工具
RUN apk update && apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        curl-dev \
        imagemagick-dev \
        libtool \
        libxml2-dev \
        postgresql-dev \
        sqlite-dev \
	libmcrypt-dev \
        freetype-dev \
        libjpeg-turbo-dev \
        libpng-dev \
    && apk add --no-cache \
        curl \
        git \
        imagemagick \
        mysql-client \
        postgresql-libs \
        nodejs \
        nodejs-npm \
        #视频处理
        ffmpeg \
        #运算
        php7-bcmath \
    # 配置npm中国镜像
    && npm config set registry https://registry.npm.taobao.org \
    && pecl install imagick \
    && pecl install mcrypt-1.0.1 \
    && docker-php-ext-enable mcrypt \
    && docker-php-ext-enable imagick \
    && docker-php-ext-install \
        curl \
        mbstring \
        pdo \
        pdo_mysql \
        pdo_pgsql \
        pdo_sqlite \
        pcntl \
        tokenizer \
        xml \
        zip \
        #性能提升,需要在php.ini文件中开启opcache相关配置
        opcache \
	&& docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" \
    iconv \
    #mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" gd \
    && pecl install -o -f redis \
    && rm -rf /tmp/pear \
    && docker-php-ext-enable redis

# 安装memcached
RUN apk add libmemcached libmemcached-dev \
    && git clone https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached \
    && docker-php-ext-configure /usr/src/php/ext/memcached \
        --disable-memcached-sasl \
    && docker-php-ext-install /usr/src/php/ext/memcached \
    && rm -rf /usr/src/php/ext/memcached

# 安装composer并允许root用户运行
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_NO_INTERACTION=1
ENV COMPOSER_HOME=/usr/local/share/composer

RUN mkdir -p /usr/local/share/composer \
	&& mv /usr/local/bin/composer.phar /usr/local/bin/composer \
    # 配置composer中国全量镜像
    && composer config -g repo.packagist composer https://packagist.phpcomposer.com

WORKDIR /data/www

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