Symfony 4 Doctrine can't connect to Docker MySQL Symfony 4 Doctrine can't connect to Docker MySQL docker docker

Symfony 4 Doctrine can't connect to Docker MySQL


Try this :

doctrine:    dbal:        # configure these for your database server        driver: 'pdo_mysql'        server_version: '8.0.15'        charset: utf8mb4        default_table_options:            charset: utf8mb4            collate: utf8mb4_unicode_ci        url: '%env(resolve:DATABASE_URL)%'

The mysql image is at the latest version of mysql.

The php image is missing the pdo_mysql driver

it should be added in the Dockerfile like follows :

RUN docker-php-ext-install pdo pdo_mysql zip

After this, the image has to be rebuilt with the command :

docker-compose build


juste replace mysql by sf4_mysql because you must apply the container name (container_name: sf4_mysql) in your host==>

DATABASE_URL=mysql://root:root@mysql:3306/sf4 by DATABASE_URL=mysql://root:root@sf4_mysql:3306/sf4