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

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,并且我希望我的容器尽可能准备好.

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

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...