简体   繁体   English

如何通过Dockerfile中的Composer for Symfony项目安装依赖项?

[英]How to install dependencies via Composer for Symfony project in Dockerfile?

I've met a problem related to making Docker container image, that contains Symfony base application. 我遇到了一个与制作包含Symfony基本应用程序的Docker容器映像有关的问题。 I can install php extensions without any problem (mcrypt, pdo_mysql, etc), but I can't install dependencies via Composer. 我可以毫无问题地安装php扩展(mcrypt,pdo_mysql等),但是我不能通过Composer安装依赖项。

So... I've got, that I have problems related to caching and forming file autoload.php . 所以...我有与缓存和形成文件autoload.php有关的问题。 I can't understand why, but it tries connect database. 我不明白为什么,但是它尝试连接数据库。 I assume it, because I get following message: 我认为这是因为我收到以下消息:

    Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception


      [RuntimeException]
      An error occurred when executing the "'cache:clear --no-warmup'" command:

        [Doctrine\DBAL\Exception\ConnectionException]
        An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory


        [Doctrine\DBAL\Driver\PDOException]
        SQLSTATE[HY000] [2002] No such file or directory


        [PDOException]
        SQLSTATE[HY000] [2002] No such file or directory

I've tried to install by command composer install --no-scripts --no-autoloader and it is finished successful. 我尝试通过命令composer install --no-scripts --no-autoloader进行安装, composer install --no-scripts --no-autoloader成功完成。 But I can't install assets without file autoload.php. 但是,如果没有文件autoload.php,我将无法安装资产。

Is it possible install to Docker container image with Symfony based project dependencies and assets? 是否可以将基于Symfony的项目依赖项和资产安装到Docker容器映像中? Thank you! 谢谢!

One of your bundles in the AppKernel requires a database connection during the compilation of the kernel (warming up the cache). AppKernel一个捆绑软件在内核编译(预热缓存)期间需要数据库连接。 You will need to debug which of the bundles does this by disabling them one at the time. 您将需要通过一次禁用它们来调试哪个捆绑软件。

Probably if you disable all of them (except for the Symfony ones) building the container works just fine. 可能如果您禁用所有这些功能(Symfony除外),则构建容器就可以了。

So the problem basically lies in these two lines of the post-install-cmd , for my project on Platform.sh removing these lines allowed me to build the container: 因此,问题基本上出在post-install-cmd这两行中,对于我在Platform.sh上的项目,删除这些行使我可以构建容器:

"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM