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