Docker Community Forums

Share and learn in the Docker community.

Please delete - Trouble with Redis + NodeJS / Express + Docker-Compose


Never mind, it seems to be working now. Problem had to do with figuring out the correct host to supply to the Redis client in Node. Please delete.

I’m using Docker Toolbox. For the life of me I can’t get Redis to work with Docker-Compose.

First I tried to dockerize a complex app of mine that works perfectly in a local environment. Redis didn’t work with that docker-compose. When Node/Express reaches out to get data from Redis it doesn’t do anything. No errors, it’s just never able to get any set data in the cache. The other parts of the app work fine, like PostgreSQL. The Redis initialization output stops at these lines:

redis_1 | 1:C 12 Jan 2019 00:33:34.486 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 12 Jan 2019 00:33:34.486 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
dockertest_1 | waiting 15 seconds for redis:6379
redis_1 | 1:C 12 Jan 2019 00:33:34.486 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 12 Jan 2019 00:33:34.489 * Running mode=standalone, port=6379.
redis_1 | 1:M 12 Jan 2019 00:33:34.490 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 12 Jan 2019 00:33:34.490 # Server initialized
redis_1 | 1:M 12 Jan 2019 00:33:34.490 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.
redis_1 | 1:M 12 Jan 2019 00:33:34.491 * DB loaded from disk: 0.000 seconds
dockertest_1 | redis:6379 is available after 0 seconds

It never says “ready to accept connections” or whatever Redis usually says.

So I tried using a bare-bones NodeJS / Express app to see if I’m missing something in the complexity, all it does is start the app and put a string into Redis and try to take it out a few seconds later, but it doesn’t work there either. It doesn’t throw an error about not being able to connect to Redis. It does if I put in the wrong host.


FROM node:10.15.0-alpine

WORKDIR /usr/src/app

COPY [“package.json”, “package-lock.json*”, “./”]

RUN apk update && apk add bash

RUN npm install

COPY . .



version: ‘3’

image: dockertest
build: .
- “4000:4000”
- default
command: ‘./ redis:6379 – npm start’
- redis
image: ‘redis:alpine’
- REDIS_HOST=redis
- “6379:6379”
- default

Node app

const express = require(‘express’);
const redis = require(‘redis’);
const redisClient = redis.createClient({ host: ‘redis’ });

const app = express();

setTimeout(() => {
redisClient.set(‘abc’, ‘defg’, ‘EX’, ‘30’);
console.log(‘Set value’);

setTimeout(() => {
redisClient.get(‘abc’, (val) => {
if (!val) {
console.log(“Didn’t work again”);
console.log('Got value: ', val);
console.log('Val2: ', val2);
}, 3000);
}, 3000)

app.listen(4000, () => {
console.log(“Server’s up”)

I tried with and without volumes set up, conf files included, both wait-for-it and wait-for, and I’m about ready to give up on Docker.