Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

php symfony in docker

I have a dockerfile to start a symfony server. The Dockerfile contains:

RUN composer install --optimize-autoloader
RUN APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear --env=prod
RUN php bin/console doctrine:schema:update --env=prod --dump-sql --force

If build it in the docker network with the mysql running, it runs fine. But if i build it wihthout the mysql being available it fails because:

ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!  PHP Fatal error:  Uncaught PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
!!  Stack trace:
!!  #0 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(27): PDO->__construct('mysql:host=mysq...', 'USER', 'PASSWD', Array)
!!  #1 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php(25): DoctrineDBALDriverPDOConnection->__construct('mysql:host=mysq...', 'USER', 'PASSWD', Array)
!!  #2 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(362): DoctrineDBALDriverPDOMySqlDriver->connect(Array, 'root', 'massphoning', Array)
!!  #3 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(428): DoctrineDBALConnection->connect()
!!  #4 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(388): DoctrineDBALConnection->getDatabasePlatformVersion()
!!  #5 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connecti in /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php on line 93
!!
Script @auto-scripts was called via post-install-cmd

I don't really know symfony, but I'm guessing symfony is trying to create some db pool and tries to actually make the connection to the db. But if I'm building the docker, there won't be a db server available! How can i make symfony not test the db connection?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can't understand the reason for making such logic as schema update in Dockerfile, Dockerfile should allow to create environment, contains required dependencies and nothing else.

So, please look at this https://github.com/AndreyMashukov/crassula

this is example of Symfony 5 project, I hope, it will help you. It has an example of Dockerfile with Xdebug extension for php and some tests (unit, functional) and CI example


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...