Redis Help

I am trying to get two containers to talk to one another, one with redis-server, and one with my web app.

Here is the Dockerfile for the redis image:

FROM redis:3.2.1 EXPOSE 6379 CMD [ "redis-server" ] 

Very simple, and it seems to run fine when I create the container like this:

 docker run -d --rm -p 6379:6379 e71a5e1b0f03 

(I'm not sure if I need to have `EXPOSE 6379` and the `-p 6379:6379` as well. Part of my problem is I don't understand the ports well enough.)

When I create the container for my (NodeJs) webapp, I get this error:

 Error: Redis connection to failed - connect ECONNREFUSED at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) Emitted 'error' event on RedisClient instance at: at RedisClient.on_error (/usr/src/app/node_modules/redis/index.js:406:14) at Socket.<anonymous> (/usr/src/app/node_modules/redis/index.js:279:14) at Socket.emit (events.js:210:5) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:80:21) { errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: '', port: 6379 } 

I am using boilerplate redis code in my js file:

const redis = require('redis') const client = redis.createClient({ port: 6379 }) 

As far as I understand it, my webapp container should be able to communicate with the redis container through port 6379. What am I not understanding?

I eventually will set this up with docker-compose, but I want to understand the basics before I start using tools to make things easier.

Any help is much appreciated.

submitted by /u/Briyo2289
[link] [comments]
Source: Reddit