symfony-docker icon indicating copy to clipboard operation
symfony-docker copied to clipboard

Issue related to connecting with MySQL database once docker is up

Open imlokeshs opened this issue 5 years ago • 2 comments

Hi,

Once the docker is up all the three containers are running and when I tried to connect with MySQL database. I couldn't connect with symfony framework..Kindly help me on this to proceed further.

imlokeshs avatar Aug 08 '20 14:08 imlokeshs

Have you set up the env variable for DATABASE_URL in your .env.local file inside symfony folder?

DATABASE_URL=mysql://app_user:helloworld@db:3306/app_db?serverVersion=5.7

ger86 avatar Aug 10 '20 09:08 ger86

I couldn't connect with symfony framework

I got it to work by adding a container_name for the services.db configuration in the .docker/docker-compose.yml:

...

services:
    db:
        container_name: mysql_container
        image: mysql:8.0.23
        platform: linux/x86_66
...

Then use the container name as domain name:

DATABASE_URL=mysql://app_user:helloworld@mysql_container:3306/app_db?serverVersion=8.0.23&charset=utf8mb4

goulashsoup avatar Sep 10 '22 16:09 goulashsoup