Answer the question
In order to leave comments, you need to log in
How to connect from docker container with mysql on host?
The nginx + php bundle is raised in the docker, there is a mysql database on the host machine.
I need to connect from the docker to the database on the host
. There is one root user with the specified localhost host in the database
. When connecting [email protected] with port 3306, the answer is An exception occurred in driver: SQLSTATE [HY000] [2002] No such file or directory (as I understand it, it looks for a database in the container) I
specify the ip address of the computer - timeout failure I specify
the internal ip address of the computer - An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
As I understand it, you can create a user in the database specifically for this connection with the specified docker host, but the host can change when you install the image again or deploy it on another machine...
What are the approaches to solving this problem?
The entire Internet was full of instructions on how to connect to the database that is in the container...
Answer the question
In order to leave comments, you need to log in
Make MySQL listen on all interfaces.
Add a user with a host equal to the IP of the gateway in the container.
Connect from the container to MySQL using the gateway IP.
There is another bad option - specify network: host
PS
Information for reflection: how to connect to the database from the container if it is on another server?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question