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.

  • `docker run` on a remote host
  • RavenDb - Status Code: NotFound
  • How to set an environment variable in a running docker container
  • docker build with a template Dockerfile
  • Registry: Error pushing to registry: Authentication is required
  • Can't return list of docker repository images through API
  • 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.

  • I installed a docker on osx, now bundler is horrifically slow
  • mysql docker container start with a fixed ip
  • Docker OSX Unable to Access Container via IP Address
  • Logstash with fluent input codec not working
  • Using the Spotify Maven Docker plugin, how can I change the file permissions of a resource that I add to a Docker container?
  • Rename docker machine
  • 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.