无法看到mysql数据库时,composer安装失败

时间:2014-12-16 11:13:16

标签: php symfony doctrine composer-php docker

TL; DR:当安装后脚本无法看到MySQL服务器时,composer安装失败

我正在为Symfony应用程序构建一个docker容器,在构建过程中我会做这样的事情

RUN export SYMFONY_ENV=prod && \
  composer install --prefer-dist --optimize-autoloader

在安装结束时,它失败了

Generating optimized autoload files


  [Doctrine\DBAL\Exception\DriverException]                                                                  
  An exception occured in driver: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)  

  [Doctrine\DBAL\Driver\PDOException]                                        
  SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)  

  [PDOException]                                                             
  SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)  


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.  

现在,我可以使用--no-scripts,但之后我可能需要在启动容器后再次运行composer install,并且我希望我的容器尽可能准备就绪

由于我没有找到很多类似问题的引用,我的应用程序中可能存在一些错误,我怀疑我会回答我自己的问题。我希望在描述它时,我会弄清楚。唉,我没有。欢迎提供线索:)

1 个答案:

答案 0 :(得分:5)

Doctrine介绍了一些代码,这些代码试图非常热切地自动检测数据库的内容。

解决方法只是告诉Doctrine目标服务器版本,例如

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                dbname:   Symfony2
                user:         root
                password: null
                host:         localhost
                driver:       pdo_mysql
                server_version: 5.6

请参阅https://github.com/doctrine/DoctrineBundle/issues/351#issuecomment-75456547