dongyue3795
dongyue3795
2017-10-19 09:11

未捕获的错误:在docker容器中找不到类'Memcached'

I am trying to deploy php7 slim application into docker. This is how my Dockerfile looks like:

FROM php:7.1.2-apache

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
    php composer-setup.php && \
    php -r "unlink('composer-setup.php');" && \
    mv composer.phar /usr/local/bin/composer


ADD sourcecode  /var/www/html

RUN composer install
RUN sed -i 's/DocumentRoot.*$/DocumentRoot \/var\/www\/html\/src/' /etc/apache2/sites-enabled/000-default.conf

This is snippet of code where Memcached initialized

<?php
global $config;

$cache_settings = $config['settings']['memcached'];

$memcached = new Memcached;
$memcached->addServer($cache_settings['host'], $cache_settings['port']) or die ("CANNOT connect to memcached");

I also have Memcached and Mysql containers are running. All staff is launching by docker-compose file. But when I am requesting for a page of my app, I get this error:

Uncaught Error: Class 'Memcached' not found in ...

How can I fix this issue?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dopa53272 dopa53272 4年前

    Try to add :

    RUN apt-get update && apt-get install -y libz-dev libmemcached-dev && rm -r /var/lib/apt/lists/* RUN pecl install memcached RUN echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini

    after the FROM php:7.1.2-apache

    点赞 评论 复制链接分享
  • dpy33121 dpy33121 4年前

    You might be missing the memcached package.

    You can install it as follows: apt-get install memcached

    点赞 评论 复制链接分享