moneyslow.com

基于nginx-php-fpm的docker安装php7的redis扩展memcahced扩展

docker技巧

docker技巧

镜像:https://hub.docker.com/r/richarvey/nginx-php-fpm/

php版本:FROM php:7.1.11-fpm-alpine

下载镜像并启动容器:

docker run -d richarvey/nginx-php-fpm

进入容器:

docker exec -it 08f7c84d5b84 bash

    1  php -m|grep redis

    2  mkdir -p /usr/src/php/ext/redis

    3  curl -L https://github.com/phpredis/phpredis/archive/3.0.0.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1

    4  echo 'redis' >> /usr/src/php-available-exts

    5  docker-php-ext-install redis

    6  php -m|grep redis

手工验证没问题,将命令写入dockerfile:

RUN mkdir -p /usr/src/php/ext/redis \
    && curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
    && echo 'redis' >> /usr/src/php-available-exts \
    && docker-php-ext-install redis

参考:

https://stackoverflow.com/questions/31369867/how-to-install-php-redis-extension-using-the-official-php-docker-image-approach

memcached  扩展:

参考:https://stackoverflow.com/questions/40894385/how-can-i-install-the-php-memcached-extension-on-dockers-php7-alpine-image
安装memcached扩展:
ENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-dev
RUN apk add --no-cache --update libmemcached-libs zlib
RUN set -xe \
    && apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS \
    && apk add --no-cache --update --virtual .memcached-deps $MEMCACHED_DEPS \
    && pecl install memcached \
    && echo "extension=memcached.so" > /usr/local/etc/php/conf.d/docker-php-ext-memcached.ini \
    && rm -rf /usr/share/php7 \
    && rm -rf /tmp/* \
    && apk del .memcached-deps .phpize-deps

Exit mobile version