尝试使用docker-compose通过节点连接到Redis时ECONNREFUSED

时间:2019-09-03 17:45:46

标签: node.js redis docker-compose

我正尝试切换到docker,出于某种原因,我的Node.js应用程序无法连接到在docker上运行的redis。

这是我的docker compose:

version: "3"
services:
  chatty-backend:
    container_name: chatty-backend
    build: ./
    volumes:
      - ./:/usr/src/chatty-backend
    command: npm start
    working_dir: /usr/src/chatty-backend
    ports:
      - "5000:5000"
    links:
      - redis
      - mongo
    depends_on:
      - redis
      - mongo

  mongo:
    image: mongo:bionic
    ports:
      - "27017:27017"

  redis:
    image: redis
    ports:
      - "6379:6379"
    command:
      redis-server

这是我连接到Redis的地方:

import * as Redis from 'ioredis';

const redis = new Redis({ host: 'redis', port: 6379 });

export default redis;

还尝试了new Redis('redis://redis:6379')

我当前收到此错误:

 Error: connect ECONNREFUSED 127.0.0.1:6379
   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14) {
     errno: 'ECONNREFUSED',
     code: 'ECONNREFUSED',
     syscall: 'connect',
     address: '127.0.0.1',
     port: 6379 
}

1 个答案:

答案 0 :(得分:0)

graphql-redis-subscriptions引起的问题。 我忘了通过更新的配置。