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 0.0.0.0:4400->80/tcp musing_moser
97dafcfb4acd mysql "docker-entrypoint.s…" 18 hours ago Up 2 minutes 0.0.0.0:3306->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 refused
This is parameters.yml
file:
parameters:
database_host: 127.0.0.1
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": [
"/suspicious_brattain:/musing_moser/db"
],
...
As you can see they are connected, however I still unable to create my database using symfony command and I get Connection refused
!
You shouldn't be trying to connect on 127.0.0.1
, but to db
.
When linking containers, a /etc/hosts
entry is created in the container to make configuration more convenient.