0

I have a Docker container with a Node.js app and a Redis Database which is running on the server (not in a container). In the container when the app starts I can't connect to the DB and I am getting the following errror Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 but I dont understand why because if I open redis-cli on the server and ping it answers with pong so the db is up.

roboJS
  • 33
  • 1
  • 4

1 Answers1

0

You will need to provide which network your docker should be using. To allow it connection to your host provide the network in your docker command

  --network="host"

UPDATE: Per note left in comments

Ideally you would want to host redis in a separate docker instance or as an external service. This will allow you to either use docker network setup or hit the redis instance through external IP/hostname within your internal vpc. This solution is only meant for the purpose shown above for which redis lives in the host on which the app docker image is being hosted.

Edward Romero
  • 2,905
  • 1
  • 5
  • 17
  • This generally disables Docker's networking stack and shouldn't be a general-purpose solution. – David Maze Sep 06 '20 at 16:12
  • @DavidMaze I am providing this solution to solve the problem above and not as a general solution for all docker setups. Ideally redis would live in its own docker so then we can use docker network for this. Or we would host redis in a separate external service – Edward Romero Sep 06 '20 at 16:16