问题
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?
回答1:
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
回答2:
You might be missing the memcached package.
You can install it as follows: apt-get install memcached
来源:https://stackoverflow.com/questions/46826441/uncaught-error-class-memcached-not-found-in-docker-container