Why am I getting ECONNREFUSED connecting to localhost MySQL from docker node app?

I have a locally running MySQL server.. it’s NOT within a container. My app is going to be hitting RDS so no sense in going that route. My app was able to hit RDS no problem, as a test. But obviously I want to hit something local for local development.

From my terminal I can do mysql --user=root --password=password mydb successfully.

  • Which is the right workflow with DBs and Docker
  • Run mysql instance in Docker container
  • How to SSH into Docker?
  • Pycharm 2017.1 EAP Python Console and Remote Docker Interpreter not working together
  • MessageListenerContainer not listening after crashing master redis instance in redis sentinel in docker env
  • Docker 1.12-how to run a post deploy script after swarm deploy my service
  • And as I’m not getting a timeout error, from my container I can ping with no issue.

    I also used console to see I am definitely passing the right info, after having updated the values from RDS to locally running MySQL.

  • Bluemix `docker exec` returns 404
  • Docker: setup proxy to download images
  • Trick to loop/autorefresh docker ps view like top/htop in bash
  • docker-py getarchive destination folder
  • Docker Swarm - Can’t pull from private registry
  • Why this docker file is not running with a shell script?
  • One Solution collect form web for “Why am I getting ECONNREFUSED connecting to localhost MySQL from docker node app?”

    Docker container has its own network IPs, including its own localhost. So you basically need to be sure of two things:

    1. That your host MySQL is listening in all of its interfaces (bind-addres = in my.cnf). Check with netstat -na|grep 3306.

    2. Figure out the host ip that your container can reach. So check the IP of the container: docker inspect container-id, find the IP, and replace the last part with .1, that should be the IP of your host in the containers own network. I.e. (it can be considered as fixed IP, for dev environment it’s ok)

    So most likely that this is what you need:

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