Can’t link symfony app container to mysql container

I have a tow running containers one with symfony app and the other is mysql database server:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
99d17c328612        sbc/gestcom:1.0     "docker-php-entrypoi…"   18 hours ago        Up 2 minutes>80/tcp                musing_moser
97dafcfb4acd        mysql               "docker-entrypoint.s…"   18 hours ago        Up 2 minutes>3306/tcp, 33060/tcp   suspicious_brattain

I linked mysql container to symfony contianer like so:

docker container run -d -p 4400:80 --link suspicious_brattain:db sbc/gestcom:1.0

suspicious_brattain: is the name of the mysql container
sbc/gestcom:1.0: is the name of the image I built that contains my symfony app (with apache, php and pdo driver needed to work with mysql)
Now when I access the symfony app container to run doctrine:database:create I get this exception:

In AbstractMySQLDriver.php line 93:

An exception occurred in driver: SQLSTATE[HY000] [2002] Connection

This is parameters.yml file:

    database_port: 3306
    database_name: my_database
    database_user: root
    database_password: root

Of course I gave root as password for mysql image when running it like so:

docker container run -e MYSQL_ROOT_PASSWORD=root -d mysql

And to be sure that the symfony container is linked to mysql container this what I get when I inspect the symfony container:

"Links": [

As you can see they are connected, however I still unable to create my database using symfony command and I get Connection refused!

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *