0

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): Doctrine\DBAL\Driver\PDOConnection->__construct('mysql:host=mysq...', 'USER', 'PASSWD', Array)
!!  #2 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(362): Doctrine\DBAL\Driver\PDOMySql\Driver->connect(Array, 'root', 'massphoning', Array)
!!  #3 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(428): Doctrine\DBAL\Connection->connect()
!!  #4 /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(388): Doctrine\DBAL\Connection->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?

2
  • Did this answer your question? stackoverflow.com/a/34024275/6759119 Commented Jan 12, 2021 at 21:17
  • 2
    RUN php bin/console doctrine:schema:update --env=prod --dump-sql --force command requires the db connection Commented Jan 13, 2021 at 11:44

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.