使用Docker安装PHP7 fpm和memcached

时间:2016-09-06 08:08:51

标签: docker memcached docker-compose dockerfile libmemcached

我有一个使用Docker的应用程序,我正在尝试使用php7-fpm安装memcached。

根据我在Dockerfile中的official docker documentation

# PHP Version
FROM php:7.0-fpm

...

# Install Memcached
RUN apt-get install -y libmemcached-dev && \
pecl install memcached && \
docker-php-ext-enable memcached

但我收到了这个错误:

pecl/memcached requires PHP (version >= 5.2.0, version <= 6.0.0, excluded versions: 6.0.0), installed version is 7.0.9

我不想切换到PHP 5.6。有什么想法吗?

3 个答案:

答案 0 :(得分:4)

我们在构建php7容器时从头开始构建memcache扩展。也许我们的接近可以帮助您或指向正确的方向。 Dockerhub中的文档看起来确实有问题,尝试过pecl并且它也没有在这里工作。

所以这就是它在我们的Dockerfile中的样子:

RUN apt-get update && apt-get install -y 
        libmemcached11 \
        libmemcachedutil2 \
        libmemcached-dev \
        libz-dev \
        git \
    && cd /root \
    && git clone -b php7 https://github.com/php-memcached-dev/php-memcached \
    && cd php-memcached \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && cd .. \
    && rm -rf  php-memcached \
    && echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini \
    && apt-get remove -y build-essential libmemcached-dev libz-dev \
    && apt-get remove -y libmemcached-dev libz-dev \
    && apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

答案 1 :(得分:2)

似乎memcached与php7不兼容,需要另外一种方法来安装它。

Laradock repo快速锁定后,我以这种方式解决了,我发布了代码:

# PHP Version
FROM php:7.0-fpm

# Install the PHP extensions we need
RUN apt-get update && \
apt-get install -y --no-install-recommends \
    curl \
    libmemcached-dev \
    libz-dev \
    libpq-dev \
    libjpeg-dev \
    libpng12-dev \
    libfreetype6-dev \
    libicu-dev \
    libssl-dev \
    libmcrypt-dev && \
    docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr && \
    docker-php-ext-install gd mysqli opcache intl

    .....

 # Install Memcached
RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-   dev/php-memcached/archive/php7.tar.gz" && \
mkdir -p memcached && \
tar -C memcached -zxvf /tmp/memcached.tar.gz --strip 1 && \
( \
    cd memcached && \
    phpize && \
    ./configure && \
    make -j$(nproc) && \
    make install \
) && \
rm -r memcached && \
rm /tmp/memcached.tar.gz && \
docker-php-ext-enable memcached

答案 2 :(得分:0)

另一个解决方案

FROM php:7.2-fpm
# ...
# INSTALL memcached
RUN apt-get upgrade -y
RUN apt-get install -y memcached
RUN apt-get install -y libmemcached-dev zlib1g-dev libicu-dev
RUN git clone -b php7 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