i have seen this question asked around a couple times, but never found a proper answer that works for me, so i will give it a go.
I have sat up a worker service in its own docker container which uses Bull Queue. Then i have redis in a seperate container. All worked fine when redis was in a container and the worker was running locally, but now the worker just prints Error connecting to Redis: Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 6379 }
Which i find kind of strange, since i am referring to the container name when i set up Bull. In fact no matter what i change the host to in the setup, it prints the same error. Unless i run the worker locally, then it prints whichever host i input. I have also tried changing the "connectionName" field without any changes.
Docker compose:
version: '3.1'
services:
redis:
image: redis:latest
restart: always
container_name: my_cache
ports:
- '6379:6379'
command: redis-server --save 20 1 --loglevel warning --requirepass pirate
volumes:
- redis-data:/data
worker:
image: worker
build: ../worker
environment:
- REDIS_HOST=local:redis:6379
ports:
- "6000:6000"
links:
- redis
volumes:
redis-data:
driver: local
queue.ts
import Bull from "bull";
export const gameEventQueue = new Bull("game-event", {
redis: {
host: 'redis',
password: "pirate"
}
});
Bull versions "bull": "^4.12.2", "bull-board": "^2.1.3",
i also tried to set ENV in docker compose like this
worker:
image: worker
build: ../worker
environment:
- REDIS_HOST=local:redis:6379
And connect like this,
import Bull from "bull";
export const gameEventQueue = new Bull("game-event", {
redis: {
host: process.env.REDIS_HOST,
password: "pirate"
}
});
But still no Joy. I appreciate all help
