How to install php-redis extension using the offic

2019-03-08 05:31发布

I want to build my PHP-FPM image with php-redis extension based on the official PHP Docker image, for example, using this Dockerfile: php:5.6-fpm.

The docs say that I can install extensions this way, installing dependencies for extensions manually:

FROM php:5.6-fpm
# Install modules (iconv, mcrypt and gd extensions)
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd
CMD ["php-fpm"]

Without Docker I installed it with apt-get install php5-redis. But how can I install it using the approach above?

8条回答
趁早两清
2楼-- · 2019-03-08 06:03

Based on @starikovs answer. I added a variable for docker style.

# install phpredis extension
ENV PHPREDIS_VERSION 2.2.7

RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \
    && tar xfz /tmp/redis.tar.gz \
    && rm -r /tmp/redis.tar.gz \
    && mv phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
    && docker-php-ext-install redis
查看更多
孤傲高冷的网名
3楼-- · 2019-03-08 06:09

I'm using combination of PECL and PHP official docker extension script

RUN pecl bundle -d /usr/src/php/ext redis \
&& rm /usr/src/php/ext/redis-*.tgz \
&& docker-php-ext-install redis

For PHP7 you need to wait for official redis pecl release or use git:

RUN apt-get update \
&& apt-get install git -y -q \
&& git clone -b php7 https://github.com/phpredis/phpredis.git /usr/src/php/ext/redis \
&& docker-php-ext-install redis
查看更多
登录 后发表回答