docker-compose setup不允许容器连接到redis

时间:2016-12-23 23:50:50

标签: node.js docker redis docker-compose kue

所以我正在编写一个节点应用程序,而我的docker-compose.yml看起来像:

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

非常简单,一个网络服务器,以及两个处理电子邮件和短信作业的工作人员。一切都很棒,直到今天下午,似乎没有什么变化,但是当我的应用程序启动时,我无法再连接到redis容器。我运行docker-compose up并尝试使用kue节点模块连接到redis时出现以下错误:

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)

我与redis的kue连接如下:

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

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

我在这里出错的任何想法?我昨晚刚刚设置了这个,电子邮件很高兴被发送,就像我提到的那样,唯一可以改变的是Web服务中的应用程序代码。我在Mac上进行开发,如果它有所作为,并拥有最新版本的docker和docker-compose。执行docker psdocker-compose up显示:

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

0 个答案:

没有答案