Docker安装带有Memcache扩展的PHP-7-fpm?失败,无法找到config.m4


Docker install PHP-7-fpm with Memcache extention ? fails with Cannot find config.m4

我正在尝试安装支持memcache的PHP 7.0版Docker,我的Docker文件如下所示,但它在STEP 10失败,错误为

Step 10 : RUN /usr/bin/phpize
 ---> Running in 450678a59cd4
Cannot find config.m4.
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
[31mERROR[0m: Service 'php' failed to build: The command '/bin/sh -c /usr/bin/phpize' returned a non-zero code: 1 

Docker文件如下

FROM php:7.0-fpm
#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 -y install php-pear php5-dev 
# Download and Installing git and vim 
RUN apt-get -y install git vim gcc
# Download and Installing zip unzip 
RUN apt-get -y install zip unzip 
# install PHP PEAR extensions 
RUN apt-get -y install wget 
#RUN wget http://pecl.php.net/get/memcache-3.0.9-dev.tgz && gunzip memcache-3.0.9-dev.tgz && tar -xvf memcache-3.0.9-dev.tar && cd memcache-3.0.9-dev '
#   && phpize && ./configure && make && make install  
# RUN git clone https://github.com/websupport-sk/pecl-memcache && cd pecl-memcache 
RUN apt-get -y install libmemcached-dev libmemcached11
RUN git clone https://github.com/php-memcached-dev/php-memcached && cd php-memcached && git checkout -b php7 origin/php7
RUN /usr/bin/phpize 
RUN ./configure && make && make install
RUN apt-get install -y memcached    
EXPOSE 9000
COPY ./www.conf /etc/php-fpm.d/www.conf
COPY ./php.ini /etc/php.ini
COPY ./php-fpm.conf /etc/php-fpm.conf
COPY ./40-memcache.ini /etc/php.d/40-memcache.ini
#COPY bootstrap.sh /opt/bootstrap.sh
#RUN chmod +x /opt/bootstrap.sh
#ENTRYPOINT ["/opt/bootstrap.sh"]

以下是Dockerfiles的外观:

PHP-FPM Dockerfile:

FROM php:7.0-fpm
# ... 
RUN apt-get update && apt-get install -y '
    libpq-dev '
    libmemcached-dev '
    curl
# ... 
# Install Memcached for php 7
RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-memcached/archive/php7.tar.gz" '
    && mkdir -p /usr/src/php/ext/memcached '
    && tar -C /usr/src/php/ext/memcached -zxvf /tmp/memcached.tar.gz --strip 1 '
    && docker-php-ext-configure memcached '
    && docker-php-ext-install memcached '
    && rm /tmp/memcached.tar.gz

# ... 
CMD ["php-fpm"]
EXPOSE 9000

Memcached Dockerfile:

FROM memcached:latest
CMD ["memcached"]
EXPOSE 11211

这是从https://github.com/LaraDock/laradock

您需要在正确的文件夹中运行命令/usr/bin/phpize
请将此Dockerfile作为示例

RUN wget https://github.com/phpredis/phpredis/archive/2.2.5.zip; unzip 2.2.5.zip
WORKDIR /tmp/php-redis/phpredis-2.2.5
RUN /usr/bin/phpize; ./configure; make; make install

在您的案例中,您确实克隆了repo php-memcached并在其中创建了cd,但这不会更改下一个Dockerfile RUN指令的工作目录。

RUN指令之前设置该工作目录:

WORKDIR /php-memcached
RUN /usr/bin/phpize 

这对我来说很有效:

FROM php:7.1.1-fpm
RUN apt-get update
RUN docker-php-ext-install mysqli
RUN 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 apt-get install git -y
RUN git --version
RUN apt-get install -y build-essential libmemcached-dev
RUN git clone https://github.com/php-memcached-dev/php-memcached.git
RUN cd php-memcached '
&& git checkout php7 '
&& phpize '
&& ./configure --disable-memcached-sasl '
&& make '
&& make install