php - docker build: fatal error :找不到类 'Memcached'

标签 php symfony docker memcached dockerfile

我正在使用symfony框架对一个项目进行docker化。发生以下错误。

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Package operations: 28 installs, 0 updates, 0 removals
  - Installing twig/twig (v1.12.1): Cloning v1.12.1
    Failed to download twig/twig from source: Your configuration does not allow connections to git://github.com/fabpot/Twig.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing twig/twig (v1.12.1): Downloading (100%)         
  - Installing doctrine/common (2.3.0): Cloning 2.3.0
  - Installing symfony/symfony (v2.1.7): Cloning v2.1.7
    Failed to download symfony/symfony from source: Your configuration does not allow connections to git://github.com/symfony/symfony.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing symfony/symfony (v2.1.7): Downloading (100%)         
  - Installing jdorn/sql-formatter (v1.2.0): Cloning v1.2.0
    Failed to download jdorn/sql-formatter from source: Your configuration does not allow connections to git://github.com/jdorn/sql-formatter.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing jdorn/sql-formatter (v1.2.0): Downloading (100%)         
  - Installing doctrine/dbal (2.3.2): Cloning 2.3.2
  - Installing doctrine/doctrine-bundle (v1.1.0): Cloning v1.1.0
    Failed to download doctrine/doctrine-bundle from source: Your configuration does not allow connections to git://github.com/doctrine/DoctrineBundle.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing doctrine/doctrine-bundle (v1.1.0): Downloading (100%)         
  - Installing doctrine/orm (2.3.2): Cloning 2.3.2
    Failed to download doctrine/orm from source: Your configuration does not allow connections to git://github.com/doctrine/doctrine2.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing doctrine/orm (2.3.2): Downloading (100%)         
  - Installing friendsofsymfony/jsrouting-bundle (1.1.2): Cloning 1.1.2
  - Installing jms/cg (1.0.0): Cloning 1.0.0
    Failed to download jms/cg from source: Your configuration does not allow connections to git://github.com/schmittjoh/cg-library.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing jms/cg (1.0.0): Downloading (100%)         
  - Installing jms/metadata (1.1.1): Cloning 1.1.1
  - Installing jms/aop-bundle (1.0.0): Cloning 1.0.0
  - Installing jms/di-extra-bundle (1.1.1): Cloning 1.1.1
  - Installing jms/security-extra-bundle (1.2.0): Cloning 1.2.0
  - Installing kriswallsmith/assetic (dev-master 5591252): Cloning 5591252faa
    Failed to download kriswallsmith/assetic from source: Your configuration does not allow connections to http://github.com/kriswallsmith/assetic.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing kriswallsmith/assetic (dev-master 5591252): Downloading (100%)         
  - Installing phpoffice/phpexcel (1.7.9): Cloning 7a7634fba6
  - Installing irongit/symfony2-stream-response (dev-master 3e5082e): Cloning 3e5082e7be
  - Installing liuggio/excelbundle (v1.0.5): Cloning 9cf3e2ec21
  - Installing kriswallsmith/buzz (v0.10): Cloning 759432d663
  - Installing sensio/buzz-bundle (dev-master 929c883): Cloning 929c883f8d
  - Installing sensio/distribution-bundle (v2.1.7): Cloning v2.1.7
  - Installing sensio/framework-extra-bundle (v2.1.7): Cloning v2.1.7
  - Installing sensio/generator-bundle (v2.1.7): Cloning v2.1.7
  - Installing symfony/assetic-bundle (v2.1.0): Cloning v2.1.0-RC2
  - Installing monolog/monolog (1.2.1): Cloning 1.2.1
  - Installing symfony/monolog-bundle (v2.1.7): Cloning v2.1.7
  - Installing swiftmailer/swiftmailer (v4.2.2): Cloning v4.2.2
    Failed to download swiftmailer/swiftmailer from source: Your configuration does not allow connections to git://github.com/swiftmailer/swiftmailer.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.
    Now trying to download from dist
  - Installing swiftmailer/swiftmailer (v4.2.2): Downloading (100%)         
  - Installing symfony/swiftmailer-bundle (v2.1.7): Cloning v2.1.7
  - Installing twig/extensions (dev-master 5c2d515): Cloning 5c2d515d46
kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the integration with the lessphp LESS compiler)
kriswallsmith/assetic suggests installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler)
kriswallsmith/assetic suggests installing leafo/scssphp-compass (Assetic provides the integration with the SCSS compass plugin)
kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic provides the integration with phpcssembed to embed data uris)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
Generating autoload files
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets

Fatal error: Class 'Memcached' not found in /var/www/html/gallery_core/app/cache/dev/appDevDebugProjectContainer.php on line 497
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets handling the post-install-cmd event terminated with an exception


  [RuntimeException]                                                            
  An error occurred when executing the "'assets:install '\''web'\'''" command. 

我搜索了一会儿,发现它可能没有正确安装在memcached中。但是在这里我使用的是docker,我已经构建了一个memcached服务。

Memcached dockerfile:
FROM memcached:1.4-alpine

# Port to expose (default: 11211)
EXPOSE 11211

# Default Memcached run command arguments
CMD ["-m", "128"]

# Set the user to run Memcached daemon
USER daemon

# Set the entrypoint to memcached binary
ENTRYPOINT memcached

PHP的Dockerfile
FROM php:5.6-apache

RUN apt-get update && apt-get install -y \
    git \
    unzip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version


ENV TZ=America/Los_Angeles
ENV SYMFONY_ENV='dev'
# RUN php composer.phar install --prefer-source

ENV docroot='/var/www/html'
ENV contentroot='/var/content'     


RUN mkdir $docroot/gallery_core
copy . $docroot/gallery_core/
copy php.ini /usr/local/etc/php

RUN cd $docroot/gallery_core

WORKDIR $docroot/gallery_core


RUN composer install --prefer-source

RUN cp $docroot/gallery_core/web/app_dev.php $docroot/gallery_core/web/app.php 

# install symfony symlinks
RUN php $docroot/gallery_core/app/console assets:install $docroot/gallery_core/web --symlink

# install a symlink for the assets:
RUN ln -s $docroot/gallery_core/web $docroot/gallery_core/web/gcassets

Composer.json
{
    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.1.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.1.*",
        "twig/extensions": "1.0.*@dev",
        "symfony/assetic-bundle": "2.1.*",
        "symfony/swiftmailer-bundle": "2.1.*",
        "symfony/monolog-bundle": "2.1.*",
        "sensio/distribution-bundle": "2.1.*",
        "sensio/framework-extra-bundle": "2.1.*",
        "sensio/generator-bundle": "2.1.*",
        "jms/security-extra-bundle": "1.2.*",
        "jms/di-extra-bundle": "1.1.*",
        "kriswallsmith/assetic": "1.1.*@dev",
        "friendsofsymfony/jsrouting-bundle": "1.1.*",
        "irongit/symfony2-stream-response": "dev-master",
        "liuggio/excelbundle": ">=1.0.4",
        "sensio/buzz-bundle": "dev-master"
    },
    "scripts": {
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web"
    }
}

我的问题是,如何使运行php脚本的服务能够“检测” memcached服务,就像将memcached直接安装在主机上并对php脚本服务透明一样?

最佳答案

为Docker(php-5.6)更改安装 memcached

RUN apt-get update && apt-get install -y \
    git \
    unzip


RUN apt-get update \
    && apt-get install -y git unzip zlib1g-dev libmemcached11 libmemcached-dev \
    && yes '' | pecl install memcached-2.2.0 \
    && docker-php-ext-enable memcached \
    && yes '' | pecl install memcache \
    && docker-php-ext-enable memcache

并重建php容器,这将为php安装memcache和memcached扩展

关于php - docker build: fatal error :找不到类 'Memcached',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44596075/

相关文章:

php - 如何在 Telegram 上分享网站上的图像?

php - 注释路线在 symfony 4.2.8 中不起作用

docker - Gcloud Kubernetes 连接拒绝公开服务

php - 如何在 Laravel 4 中结合使用 Ajax 和 jQuery?

PHP缓存mysql还是完整的html?

Javascript beforesend 函数在所有 "add to cart"按钮上错误显示

mongodb - Docker中的Symfony应用程序不起作用

symfony - 如何在 PHP View 中访问配置参数?

linux - 尝试运行 bash 脚本时“找不到命令”

docker 安装 lvm 插件