Home > Mobile >  How can I connect to my MariaDB running in Docker?
How can I connect to my MariaDB running in Docker?

Time:12-23

I've spun up a MariaDB container locally on my dev machine to have a look at it, but I'm not able to connect.

Docker command:

docker run --name mariadbtest -p 3306:3306 -v C:\\docker\\mariadb:/var/lib/mysql -e MARIADB_ROOT_PASSWORD=yolo123 -d mariadb:latest

If I run the command I get the IP (172.17.0.3):

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mariadbtest

It's running just fine and the logs states is ready for connection. I installed HeidiSQL and tried to connect to it but it states it can't connect. I also wrote a small c# app but it's the same story.

If I inspect it in Docker desktop app it states is bound to 0.0.0.0:3306

Is it suppose to be bound to that IP, anything else that is wrong?

CodePudding user response:

The fact a service is bound to 0.0.0.0 doesn’t really mean it will listen on that address. It actually isn’t a proper address, it’s a notation used to express that a service should listen on all available interfaces.

In your case - your container is exposing its port 3306 to the host port 3306, so you should be able to connect to 127.0.0.1:3306 (IP:PORT).

Caveat - it seems that you’re running on Windows, so you might need to modify some firewall settings to make it work (try disabling the firewall and check if you can connect, then reenable it and figure out the rules you have to change)

  • Related