Yurii Yurii - 3 months ago 49
MySQL Question

Cannot connect to MySQL server inside Docker

First I run mysql image:

docker run -e MYSQL_ROOT_PASSWORD=password -d -p mysql

Then I use container bash (where
is a random named assigned to container by docker itself):

docker exec -it big_golick bash

In Bash I can successfully connect to MySQL server via command:

mysql -uroot -ppassword

But when I try to connect to MySQL container from Windows cmd:

mysql -uroot -ppassword -h127.0.0.1 -P3308

ERROR 2003 (HY000): Can't connect to MySQL server on '' (10061)

If I connect to
instead (this ip is returned by
docker-machine ip
), then the result is the same.

The question is: How do I correctly expose my MySQL port inside Docker to outside Windows?


The error is in your port mapping in the original docker run command, you just need to provide the ports, not the IP address:

docker run -e MYSQL_ROOT_PASSWORD=password -d -p 3308:3306 mysql

You can run docker ps -a to check for the port mapping in the running containers.

You should now be able to connect to MySQL using

mysql -uroot -ppassword -h192.168.99.100 -P3308