Im running redis on my server (Redis is not running in a container) and I am trying to connect to redis inside of my Container which has a Node.js app runninng. When starting the Docker Container with the node app from my Dockerfile in the logs there is the following error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
Asked
Active
Viewed 3,328 times
2

roboJS
- 33
- 1
- 4
-
1`ECONNREFUSED` means port `6379` already is in use – aRvi Sep 06 '20 at 13:55
-
Yes it is used by Redis on the server when I do redis-cli ping on the server it answers with pong. So the redis-server works but in the node app in my docker container i cant connect – roboJS Sep 06 '20 at 14:17
-
Which OS are you using? – eol Sep 06 '20 at 15:52
1 Answers
1
Docker now provides a custom DNS-name called host.docker.internal
for Windows/Mac versions (see https://docs.docker.com/docker-for-windows/networking/#use-cases-and-workarounds) which resolves to the internal IP address of the host.
So instead of using localhost:6379
/127.0.0.1:6379
in your connection string, change it to host.docker.internal:6379
.
Note: for Linux there's a workaround -> see https://stackoverflow.com/a/61424570/3761628

eol
- 23,236
- 5
- 46
- 64