Accessing docker container mysql databases

I finally found a solution and it was pretty simple...

First of all, I need to let mysql bind external address, so I changed the line bind-address to '0.0.0.0' inside the container. Next I just changed the command line with mysql -h 127.0.0.1 -P 3308 -u root -pMyPassword

Now it's fine, I can access container mysql data from the host.

Thanks all for your help :)


In my case I was confused because docker used a different host and port. So you need to find them then do this:

mysql -P <portnumber> -h <host IP> -u db_name -p

Most people would put the docker DB related variables into the environment of the docker container so do this:

sudo docker exec -it container_name env

See if there's a variable called DB_HOST or DB_PORT or something like that. If not then look thru the source code. If it's a PHP project then find a config directory and look in main.php and see