2

So I'm writing a node application, and my docker-compose.yml looks like:

version: '2'
services:
  redis:
    image: "redis:latest"
  web:
    build: .
    ports:
     - "3000:3000"
    volumes:
     - .:/app
    links:
     - redis
  emailworker:
    build: .
    env_file:
      - ./.env
    command: node ./lib/workers/email.js
    volumes:
      - .:/app
    links:
      - redis
  smsworker:
    build: .
    env_file:
      - ./.env
    command: node ./lib/workers/sms.js
    volumes:
      - .:/app
    links:
      - redis

Pretty straight forward, a webserver, and two workers to process email and sms jobs. All has been great, until this afternoon, where nothing seemed to change, but I can not longer connect to the redis container when my app boots up. I run docker-compose up and I get the following error when trying to connect to redis using the kue node module:

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)

My kue connection to redis looks like:

const kue = require('kue'),
  queue = kue.createQueue({
    root: __dirname,
    redis: {
      host: 'redis',
      port: 6379
    }
  });

queue.on('error', err => {
  console.log('QUEUE ERROR: ', err);
});

Any ideas where I'm going wrong here? I just set this up last night and emails were happily being sent, and like I mentioned, the only thing that would have changed is app code in the web service. I'm developing on a Mac if that makes a difference and have the latest version of docker and docker-compose. A docker ps after doing a docker-compose up shows:

CONTAINER ID        IMAGE                COMMAND                  CREATED              STATUS              PORTS                    NAMES
3af92333ad53        expapi_web           "yarn docker"            About a minute ago   Up About a minute   0.0.0.0:3000->3000/tcp   expapi_web_1
d26f1d81ad22        expapi_emailworker   "node ./lib/workers/e"   About a minute ago   Up About a minute   3000/tcp                 expapi_emailworker_1
1695ec819777        expapi_smsworker     "node ./lib/workers/s"   About a minute ago   Up About a minute   3000/tcp                 expapi_smsworker_1
5cb6701f3586        redis:latest         "docker-entrypoint.sh"   About a minute ago   Up About a minute   6379/tcp                 expapi_redis_1
Greg
  • 6,453
  • 9
  • 45
  • 61
  • Have you tried running ```docker-compose up --build``` to rebuild the image? I don't know this will help but maybe worth a shot. – david_i_smith Dec 24 '16 at 00:29
  • Thanks @david_i_smith, I did try and rebuild, it skips the redis image as "Redis is just using an image, skipping". The other apps rebuild, and the problem continues. – Greg Dec 24 '16 at 01:30
  • What version of docker are you running? What output do you see if you `docker exec -it $cont_id ping redis`? – BMitch Dec 24 '16 at 03:48
  • Hi @BMitch, thanks for the response. So, I'm getting 0% packet loss when I ping the redis container (I'm assuming that's which container you meant with $cont_id): 5 packets transmitted, 5 packets received, 0% packet loss – Greg Dec 24 '16 at 07:26
  • @BMitch realized it made more sense to do that ping from the `expapi_web` container :) Still get 0% packet loss. 4 packets transmitted, 4 packets received, 0% packet loss – Greg Dec 24 '16 at 07:46
  • @BMitch I suppose that means that networking with the docker containers is working as expected, which means it's got to be something to do with the app...curiouser and curiouser. – Greg Dec 24 '16 at 07:53
  • Welp, I just found I added a few pieces of kue middleware for `kue-ui` and removing that fixes the issue. Not sure how it was working before, and not now, but here we are. I'll digg a little on this but at the moment it's back to working. Thanks @BMitch and @david_i_smith – Greg Dec 24 '16 at 08:01
  • I was looking for the ping output itself from the kue container because in your error log above, it shows you trying to connect to redis on 127.0.0.1 which means dns isn't being used or its setup wrong. I suspect you have an app setting pointing to localhost instead of redis somewhere. – BMitch Dec 24 '16 at 10:12
  • how did you resolve this? I have the same error – user269867 Oct 05 '17 at 21:39

0 Answers0