kablanfatih
kablanfatih

Reputation: 513

How to connect my host mysql in docker container?

my.cnf configured = bind-address = 172.18.0.3(Docker Container ID) and bind-address = 0.0.0.0 in my host. I try connecting from docker container.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=default
DB_USERNAME=root
DB_PASSWORD=root

But not connecting local mysql.I get this error

SQLSTATE[HY000] [2002] Connection refused

Upvotes: 2

Views: 814

Answers (2)

Arun s
Arun s

Reputation: 945

If you want to connect to your local database , you call give host.docker.internal in the place where we provide database url . Then give the db you want to specify along with db username and db password.

Upvotes: 3

Munish
Munish

Reputation: 1627

  1. You can use the docker0 interface IP address
    run ip route show | awk '/default/ {print $3}' inside your container and check the ip address. try to connect on this IP address and port 3306.
  2. If you have static a host IP address then you can also use host machine IP address to connect.

Upvotes: 0

Related Questions