无法查看mysql数据库时,composer安装失败 [英] composer install fails when unable to see mysql database
问题描述
TL; DR:安装后脚本看不到MySQL服务器时,作曲家安装失败
我正在构建一个一个Symfony应用程序的docker容器,在构建过程中我做类似的事情
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.
现在,我可以使用-无脚本
,但是大概在启动一个容器之后,我需要再次运行 composer install
,我希望我的容器尽可能地准备就绪。
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.
由于我没有找到很多类似问题的参考,因此我的应用程序中可能有错误,我怀疑自己会回答我的问题。我希望在描述它时能弄清楚。 las,我还没有。欢迎线索:)
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 :)
推荐答案
Doctrine引入了一些代码,这些代码试图非常自动地自动检测有关数据库的内容。
Doctrine introduced some code which tried to auto-detect things about the database quite eagerly.
一种解决方法只是告诉Doctrine目标服务器版本,例如
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
参见 https://github.com/doctrine/DoctrineBundle/issues/351#issuecomment- 75456547
这篇关于无法查看mysql数据库时,composer安装失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!