-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to connect to redis, when running inside of docker container #763
Comments
Have you tried connecting to Redis via host "redis" (see https://docs.docker.com/compose/networking/)? const redis = require('ioredis')
const appdb = new redis({host: 'redis'})
module.exports = { db } |
Hey, @luin thanks for quick reply, I will try it and comment back in the issue in a second. Thank you |
Still fails, but now with this error:
|
Will, that is a network problem and it should not be related to ioredis. |
Ok, then I will try to hack around on my docker machine. Thank you |
@mishushakov Try delete the networks and replace redis section by: redis:
image: redis:latest
command: ["redis-server", "--bind", "redis", "--port", "6379"] That works for me. |
Same problem for me, it's still exist I've tried all suggestions above. Who can help me to resolve this, please. |
It's ok after I run |
Hey! How about running redis without docker-compose? I mean, running only the image. I lift the redis container using |
You saved me tonight |
Unfortunately did not work for me. Below is my docker-compose.yml file below is my app.js package.json file references to ioredis, |
I'm having a similar issue, and I've tried it a few different ways as suggested here. |
Try using something like this, i dont see you using the port no to connect in place of host you can simply use 'redis' |
After couple of days of stuck today my project is running in your way. Thanks ! |
This still doesn't works for me, throwing this error. |
you save my life |
The same issue, any solution for this problem? Thanks. version"ioredis": "^4.17.3",
"typescript": "^3.8.3" docker-composeversion: "3"
networks:
dev_env_network:
driver: bridge
services:
redis:
container_name: redis
image: redis:6.0-alpine
restart: always
ports:
- 6379:6379
volumes:
- redis:/data
networks:
- dev_env_network
auth-service:
container_name: auth-service
image: node:12
working_dir: /app
env_file: .env
environment:
- PG_DB=auth-service
ports:
- 50002:50002
volumes:
- ../auth-service:/app
- ../auth-service/node_modules:/app/node_modules
networks:
- dev_env_network
command: yarn start:dev applicationimport Redis from 'ioredis';
const redis = new Redis({
host: 'redis',
port: 6379,
}); errorError: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
} |
|
For those who still have an issue here, my docker compose setup is/was configured with a bridged network setup. Adding Redis to the bridged network was required to allow it's network peers to connect:
Then connecting from my docker-hosted Node app with:
If you want to then bind from the host machine, add in the requisite docker-compose port binding to the
HTH! |
You saved my life too, spent many days to fix this nodejs code, and it looks like it was caused by the docker used in my QNAP container station. redis: |
I fix this issue changing the
and send this file to container, using compose just link this volume
|
For others whose issue wasn't fixed by the above, this stackoverflow answer worked for me https://stackoverflow.com/a/58891367 If you're trying to connect from an app running in a container e.g. node app to redis running in a docker container, then the host string you set in your node app will need to be the name of your redis service name. |
you are a saviour indeed |
Solution Then rebuild ur docker with => docker-compose up --build Works!! thanks |
Following seems related: StackExchange/StackExchange.Redis#1002 |
inside my docker-compose.yml:
and inside my code:
// not sure if I need this or what this should be if we are in legacy mode. use host and port ??? redisClient.on("error", (err) => console.log("Redis Client Error", err)); redisClient.connect(); now I get
|
@cindyloo Were you able to resolve the connection issue? I have been having the same. |
I don't know why, neither if I'm doing something wrong, but what worked for me was put the same name to
cache:
image: redis
restart: always
command: redis-server --requirepass ${REDIS_PASSWORD}
container_name: ${REDIS_HOST} # getting name from .env file
export const redis = new Redis({
port: Number(process.env.REDIS_PORT) || 6379,
host: process.env.REDIS_HOST, // getting the same name from .env file
password: process.env.REDIS_PASSWORD
}); I just could notice that after @luin comment, so thanks fot that! |
Update: 26 July 2023 My docker-compose looks like this
Passing the REDIS url through the Backend like this
.env looks like this
and using it in Node
|
Thank you so much for sharing your knowledge! You save my day🙏🏻🙏🏻🙏🏻 |
I am getting the same error, but none of the above steps are working, please help! version: "3.8" redis-stack-server: minio: talawa-api-dev: caddy: volumes: networks: I am setting up a repository in my local system and followed the steps mentioned. |
Update redis-stack-server:
image: redis/redis-stack-server:latest
command: ["redis-server", "--bind", "redis-stack-server", "--port", "6379"]
ports:
- 6379:6379
volumes:
- redis-data:/data/redis
networks:
- talawa-network |
For anyone still suffering from this, use Nodejs example: createClient({url: `redis://redis:6379`}); |
Hey, the library works like a charm, thanks a lot. My application is a microservice, which connects to a redis database, which is running inside of docker. However, I can not connect to redis, when my application is running inside of container. I can still connect to redis remotely via cli on other host and it clearly works. I can also run my application outside of docker (directly on my host machine) and it would still connect. But when I build and run the image, it says:
I also tried to provision my application to docker swarm with compose file on the same network as redis
But it still wouldn't connect
Here is the code, I use in my application:
Thank you in advance.
The text was updated successfully, but these errors were encountered: