2014-12-16 11:13
浏览 75


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

  An exception occured in driver: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '' (111)  

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

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

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

  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.

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


    解决 无用
    打赏 举报

相关推荐 更多相似问题