-1

I am trying to run a Node.js app in docker. I am using WSL and have created docker images for the Node.js app, MySQL, and PhpMyAdmin. Now when I run the Node.js app I am getting the error Error: connect ECONNREFUSED 127.0.0.1:3306. Is it because MySQL is running on a different image? Is it possible to connect with MySQL on the wamp server? I have followed the tutorial here for containerizing MySQL. For running Node.js I am using the following command.

docker build -t gdns/node-app .

winpty docker run \
    -it \
    --rm \
    -v ${PWD}:/app \
    -v /app/node_modules \
    -p 4001:4000 \
    -e CHOKIDAR_USEPOLLING=true \
    gdns/node-app

Please help.

Akhilesh
  • 1,243
  • 4
  • 16
  • 49
  • The MySQL container has a different IP address than the node container, so you can't use `localhost`. If you need more help than that, then please post more about how you run your containers. – Hans Kilian Nov 23 '21 at 13:32
  • I have added the details. – Akhilesh Nov 23 '21 at 14:08
  • 1
    It'd be helpful if you could extend the question further to include the connection details from your example and a [mcve] in general; just the `docker run` command isn't really enough to reproduce anything. Does [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) (configure the database location to `host.docker.internal`, not `localhost`) help? – David Maze Nov 23 '21 at 14:29
  • Can you elaborate as to why you’ve configured your Node application to communicate with a server running on port `3306` when your configuration clearly stipulates your container’s port `4000` should be published on your host’s port `4001`? Neither of these ports are standard, can you confirm you’ve configured the instance of MySQL has been properly configured to listen on `4001` within your container? – esqew Nov 23 '21 at 14:45
  • @esqew That is for node app, not MySQL – Akhilesh Nov 23 '21 at 15:24
  • @DavidMaze Thanks! It worked! But it connects to the Wamp server's MySQL service. Is there a way I can connect to the docker MySQL container? – Akhilesh Nov 23 '21 at 15:25

1 Answers1

0

I was able to connect with the docker image using the --link option as described here. We can also use the --net option to use the same bridge network. https://docs.docker.com/network/bridge/

Akhilesh
  • 1,243
  • 4
  • 16
  • 49