Docker Community Forums

Share and learn in the Docker community.

Access MysqlServer on host from inside container

Hey!

I’m new working with docker and on the forum, i already saw some post about my issue, but none of the solutions solved my case… :confused:
I have a simple ubuntu container with apache and a symfony 3 project, i’m trying to connect my symfony website to my host machine mysql server, but whenever i try to, the ip shown in the PDO connection error message is not the one provided, it is the container address (172.17.0.2 in my case) which is the ip i find in the host machine iptables.
(Even with a simple ‘new PDO’ connection in a CLI script, i got the error: PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user ‘root’@‘172.17.0.2’ (using password: YES) in /var/www/test.php:6 )

I tried to ACCEPT Docker’s FORWARD for the mysql port in my iptables but nothing works, i may say that i tried with the real IP address and the domain name. whenever i ping the domain name i got the right ip adress but the PDO still gives the same error :confused:

Have you guys any idea?

Answer found after many searches!!

It came from the order of my rules in my iptables