I have a Node.js application where I use Redis, I am trying to connect the Docker container and the locally running Redis.
Tried solutions:
vim /usr/local/etc/redis.conf
Updated
bind 127.0.0.1
To
bind 0.0.0.0
Stopped the redis and start it again and tried running the docker
With the above thing tried running
docker run -p 4000:8080 -p 6379:6379 -t node-app
Both above didn't worked getting the below error
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
Update: I am checking it on Mac.
redis
instance to localhost instead of0.0.0.0
. Verify you can connect from docker host to redis before starting working with docker. Then stop and rm all running containers ofnode-app
. Finally start docker containerdocker run --network="host" -t node-app
. It should work. Note it is not required to specify exposed ports as with network mode host all container's exposed ports are automatically exposed to docker's host. – Diegodiehard