douyue1481 2014-12-16 11:13
浏览 77
已采纳

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

TL;DR: composer install fails when the post-install scripts can't see a MySQL server

I'm building a docker container for a Symfony application, and during the build I do something like this

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

Towards the end of the install, it fails with this

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.  

Now, I could use --no-scripts but then presumably I'd need to run composer install again after starting a container, and I'd like my container to be as ready as possible.

As I've not found many references to similar problems, there might be something in my application at fault, and I suspect I'll be answering my own question. My hope was that in describing it, I would figure it out. Alas, I haven't. Clues are welcome :)

  • 写回答

1条回答 默认 最新

  • douhuang1852 2014-12-16 17:56
    关注

    Doctrine introduced some code which tried to auto-detect things about the database quite eagerly.

    A workaround is simply to tell Doctrine the target server version, e.g.

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

    See https://github.com/doctrine/DoctrineBundle/issues/351#issuecomment-75456547

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline