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

I am trying install Docker with PHP version 7.0 with memcache support, my docker-file is as below, however it fails @STEP 10 with error

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 file is as below

  • Why are <none> images created and why doesn't Docker clean them up?
  • Error starting datanode on hadoop
  • Is there a docker image which is similar (or the same) as AWS EC2 AMI?
  • `docker run ubuntu:14.04 /bin/echo` produces SELinux error on Fedora 20
  • Configuring wercker.yml to run unit tests in a python app requiring postgres service
  • docker does not run on windows error
  • 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"]
    

  • Installing specific version of docker
  • My Docker container does not have IP address. Why?
  • npm not working after export MSYS_NO_PATHCONV on Git Bash
  • Separate Dev and Production instances and database
  • Shutting down Docker containers via supervisor
  • multiple app nodes how to expose jmx in kubernetes?
  • 3 Solutions collect form web for “Docker install PHP-7-fpm with Memcache extention ? fails with Cannot find config.m4”

    You need to run that command /usr/bin/phpize in the right folder.
    See this Dockerfile as an example

    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
    

    In your case, you did clone the repo php-memcached and make a cd in it, but that does not change the working directory for the next Dockerfile RUN directive.

    Set that working directory before the RUN directive:

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

    Here’s how your Dockerfiles should look like:

    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
    

    This is taken from https://github.com/LaraDock/laradock

    This work for me:

    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
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.