Docker - 安装php-memcached扩展无法正常工作?

时间:2016-04-11 13:34:07

标签: php nginx docker docker-compose dockerfile

我一直在尝试在我的php-5.6容器中安装memcached,但是我无法让它工作,因为我没有在phpinfo()中看到memcached扩展,并且由于某种原因它加了抱怨它无法在代码中找到memcache.so。

我的用于php build的docker文件

FROM php:5.6-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd     

RUN docker-php-ext-install mysqli mbstring pdo_mysql 

# Download and Installing php libraries 
RUN apt-get install -y memcached
RUN apt-get -y install php-pear php5-dev php5-memcached geoip-bin geoip-database libgeoip-dev php5-geoip

# Download and Installing php libraries 
RUN pecl install geoip

# Download and Installing git and vim 
RUN apt-get -y install git gcc  

RUN pwd
RUN git clone --depth=1 git://github.com/phalcon/cphalcon.git 
WORKDIR /var/www/html/cphalcon/build
RUN ./install

EXPOSE 9000
EXPOSE 11211

COPY ./php-fpm.d/www.conf /etc/php-fpm.d/www.conf
COPY ./php.ini  /usr/local/etc/php/php.ini 
COPY ./php-fpm.conf /etc/php-fpm.conf
COPY ./phalcon.ini /usr/local/etc/php/conf.d/phalcon.ini
COPY ./geoip.ini /usr/local/etc/php/conf.d/geoip.ini
COPY ./memcached.ini /usr/local/etc/php/conf.d/memcached.ini

我的docker撰写文件是

nginx:
    build: ./.config/etc/nginx/
    ports:
        - 7000:80
    links:
        - php
        - memcached:memcached            
    volumes_from:
        - app

memcached:
  image: memcached:latest   

php:
    build: ./.config/etc/php/
    expose:
        - 9000
    links:
        - mysql
        - memcached:memcached            
    volumes_from:
        - app

app:
    image: php:5.6-fpm
    #image: php:7.0-fpm
    volumes:
        - ./:/var/www/vhosts/example.com/httpdocs
    command: "true"

我在代码上遇到的错误是

[36; 1mnginx_1 | [0mPHP消息:PHP致命错误:Class' memcache'在第0行和第34行的“未知”中找不到当从上游读取响应头时,客户端:192.168.99.1,服务器:www.example.dev,请求:" GET /搜索HTTP / 1.1",上游:" fastcgi://172.17。 0.5:9000",主持人:" 192.168.99.100:7000"

这里出了什么问题?

1 个答案:

答案 0 :(得分:6)

List图像提供自定义编译的PHP,但基于Debian Jessie图像(并使用Debian的存储库)。使用php,您可以为分发的PHP软件包(沿途安装)安装apt-get install php5-memcached扩展名。

您需要通过PECL(以及通过APT构建依赖关系)安装memcached扩展名:

memcached