未捕获的错误:Class' Memcached'在docker container

时间:2017-10-19 09:11:27

标签: php docker memcached

我正在尝试将php7 slim应用程序部署到docker中。这就是我的Dockerfile的样子:

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

这是Memcached初始化

的代码片段
<?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");

我也有Memcached和Mysql容器正在运行。所有工作人员都通过docker-compose文件启动。但是,当我请求我的应用程序页面时,我收到此错误:

  

未捕获的错误:类&#39; Memcached&#39;没找到...

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

您可能缺少memcached包。

您可以按如下方式安装它:apt-get install memcached

答案 1 :(得分:0)

尝试添加:

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

FROM php:7.1.2-apache

之后