skip to Main Content

I can’t build any image with PHP-Memcached extension. All they give me an error messages and how many times I try it’s not helpful. I can’t even find any PHP Dockerfile which include memcached and it’s work. Even the main page of PHP docker page have Dockerfile with PHP Memcached solution and it’s also not working.

FROM php:5.6-cli

RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev 

&& pecl install memcached-2.2.0 

&& docker-php-ext-enable memcached

Here is my last try code

FROM php:7.4-fpm

ADD php.ini /usr/local/etc/php/conf.d/php.ini

RUN docker-php-ext-install pdo pdo_mysql

# for mysqli if you want
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

RUN printf "deb http://archive.debian.org/debian/ jessie mainndeb-src http://archive.debian.org/debian/ jessie mainndeb http://security.debian.org jessie/updates mainndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list

RUN apt-get update
RUN apt-get install -y libz-dev libmemcached-dev && 
    pecl install memcached && 
    docker-php-ext-enable memcached

Who knows about this something? Thanks, advice

2

Answers


  1. Chosen as BEST ANSWER

    Looks like I found the solution on my problem at last and it's connected with /etc/apt/source.list

    deb http://ftp.us.debian.org/debian buster main
    deb http://ftp.us.debian.org/debian buster-updates main
    

    And then just add this COPY ./sources.list /etc/apt/sourcee.list line in your Dockerfile and it will work

    FROM php:7.2-fpm
    
    COPY ./sources.list /etc/apt/sourcee.list
    

  2. I have separated memcached and phm-memcached. The first one is a container, and second is installed on Dockerfile for PHP.
    My docker-compose file :

    version: '3'
    services:
        # PHP
        php:
            build:
                context: docker/php7-fpm
            volumes:
            // etc...
    
        memcached:
            image: memcached:latest
            hostname: memcached
            networks:
                - stack
    
    

    And in my Dockerfile for PHP:

    FROM php:7-4-fpm
    
    // install dependencies...
    
    # php-memcached
    RUN set -ex 
        && rm -rf /var/lib/apt/lists/* 
        && MEMCACHED="`mktemp -d`" 
        && curl -skL https://github.com/php-memcached-dev/php-memcached/archive/master.tar.gz | tar zxf - --strip-components 1 -C $MEMCACHED 
        && docker-php-ext-configure $MEMCACHED 
        && docker-php-ext-install $MEMCACHED 
        && rm -rf $MEMCACHED
    

    And with this, in my symfony application, i can store data in memcached.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search