I am trying to develop an express api.It works on local machine as expected. I am using docker but on production with docker and heroku redis is not working
Dockerfile
FROM node:latest
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5000
CMD ["npm","start"]
docker.compose.yml file
version: '3'
services:
mongo:
container_name: mongo
image: mongo
ports:
- '27017:27017'
redis:
container_name: redis
image: redis
app:
container_name: password-manager-docker
image: app
restart: always
build: .
ports:
- '80:5000'
links:
- mongo
- redis
environment:
REDIS_PORT: ${REDIS_PORT}
MONGODB_URI: ${MONGODB_URI}
clientID: ${clientID}
REDIS_URL: ${REDIS_URL}
clientSecret : ${clientSecret}
PORT: ${PORT}
REDIS_HOST: ${REDIS_HOST}
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
JWT_EXPIRE: ${JWT_EXPIRE}
REFRESH_TOKEN: ${REFRESH_TOKEN}
JWT_REFRESH_SECRET_KEY: ${JWT_REFRESH_SECRET_KEY}
JWT_REFRESH_EXPIRE: ${JWT_REFRESH_EXPIRE}
JWT_COOKIE: ${JWT_COOKIE}
SMTP_HOST: ${SMTP_HOST}
SMTP_PORT: ${SMTP_PORT}
SMTP_USER: ${SMTP_USER}
SMTP_PASS: ${SMTP_PASS}
redis file
const asyncRedis = require('async-redis');
//process.env.REDIS_HOST's value is redis
const redisClient = asyncRedis.createClient({port:process.env.REDIS_PORT,host:process.env.REDIS_HOST || "127.0.0.1"});
redisClient.on("connect",() => { console.log(`Redis: ${host}:${port}`); })
redisClient.on('error', function(err) {console.log(`[Redis] Error ${err}`); });
I've already set REDIS_HOST variable as redis in .env file. The error on heroku is " Error: Redis connection to redis:6379 failed - getaddrinfo ENOTFOUND redis ". It worked without docker on heroku but now It is not working. Thanks for your help
Comment From: filipecosta90
@ogulcankarayel5 as seen above there is no issue related to redis on the logs ( this is a matter of using the proper env variables for reaching your redis host in production ). I suggest you ask for examples on https://github.com/moaxaca/async-redis repo and/or the community links, and we close this issue here.