Cannot connect to MySQL server inside Docker

First I run mysql image:

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

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

  • Docker 403 on push latest to private
  • Replacing sbt-native-packager with sbt-docker in Scala Play
  • Where to see the logs for a failed deployment on managed Vms on Google App Engine?
  • Docker, nginx and several sites on one server
  • Postgresql raises 'data directory has wrong ownership' when trying to use volume
  • Docker container IO performance
  • 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 '127.0.0.1' (10061)
    

    If I connect to 192.168.99.100 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?

  • Connecting to an H2 Database in a Docker Container
  • Ubuntu 16.10 : get recent docker & docker compose version?
  • eclipse che snapshot does not work
  • IBM Container deployment failure
  • Store Docker image files in external drive in El Capitan OSX
  • What are the possible states for a docker container?
  • 2 Solutions collect form web for “Cannot connect to MySQL server inside Docker”

    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
    

    First, check netstat -an to make sure the port is open in Windows. If it is, also check the Windows firewall to make sure nothing is blocking connections to the port.

    Most of my Docker experience is in CoreOS, so I’m not exactly sure how Windows handles routing traffic into the container. In CoreOS, it uses a proxy. If there is a proxy in Windows, make sure nothing is interfering with it.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.