dongyue3795 2017-10-19 09:11
浏览 77
已采纳

未捕获的错误:在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 2017-10-19 11:50
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用matlab求微分方程初值问题
  • ¥15 vscode下编写第三方库opencv与pcl代码时没有代码提示
  • ¥15 能够跑通不报错,如何解决?(标签-matlab)
  • ¥15 MOS在RDS较大,频率高时开关波形异常
  • ¥15 SCENIC分析报错求解答
  • ¥15 ceph初始化mon不成功 下图不报错 这个是什么元
  • ¥15 数学建模数学建模少ai
  • ¥35 这个等效电路图是什么意思?(答疑)(有没有不是chat的,我就是在chat搜不到才来问的,chat还开了VIP)(可以追加酬金)
  • ¥200 基于同花顺supermind的量化策略脚本编辑
  • ¥15 黄永刚的晶体塑性子程序中输入的材料参数里的晶体取向参数是什么形式的?