How do I connect to mysql on host from inside a docker container?
things I've done:
- I changed the bind-address to 0.0.0.0 so mysql would allow connetions from the docker network instead of limiting itself to 127.0.0.1
- To my docker-compose.yml, I added
- I changed my db_url string to use internal string instead of localhost.
DATABASE_URL="mysql://user:[email protected]/db_name"
from what I know that should be enough, but I can't make a connection. telnet host.docker.internal 3306
doesn't seem to work either.
What am I missing here?
Container works fine if I use host networking, so it's not the password being wrong or prisma being misconfigured - seems to be a networking issue.3 Replies
omg it was ufw being ass. now I need to figure out the rules, but disabling it seems to have fixes my issues
I'm glad to hear you could figure this out.
I havent yet, but I at least know where to look. Still need to figure out how to configure docker and firewall to play nice with eachother.
Okay so for any future people:
1.
sudo ufw allow from 172.17.0.0/16 to any port 3306
to whitelist the default docker bridge network and allow it to access port 3306 (mysql)
2. docker compose creates a unique network unless you manually specify to use the default docker bridge network.
This is how my docker-compose ended up looking like:
Note the "network_mode" and "extra_hosts:" sections
can't mark as solution, app did not respond