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?
Slightly revised version of starikovs and skyred answers for current version of the docker image. Tested on php:5-fpm-alpine
Redis is not an extension that is included in “php-src”, therefore you cannot use
docker-php-ext-install
. Use PECL:If you want to use redis as session handler;
If you want to use redis extension with PHP 7 in 2015 (borrowed from skyred's answer);
Slightly revised version of starikovs and skyred answers for the current PHP 7 version of the docker image (tested on
php:7.0.8-fpm-alpine
andphp:7.0.8-alpine
).Uses the newly released
3.0
version (June 2016) for PHP 7.I've found two ways to install php-redis extension for official php-fpm Docker image. Here they are:
The first way is to compile redis from sources and install.
docker-php-ext-install
script is included in php-fpm image and can compile extensions and install them.The second way you can do it is with PECL.
As TimWolla answered, you can do it with PECL, but in my case, PECL isn't installed by default.
My opinion, the easiest way is:
RUN pecl install redis && docker-php-ext-enable redis
;)