skip to Main Content

I’m building a small app divided in 3 services using docker I have redisjson service a node server and a python application.

I always run the redis inside a container for development, in the first stages I run the python script and the node app natively I simply used to connect to the redis using localhost.

To standardize and deploy the environment I have set up containers for each service, but the moment I tried to connect to redis from the other containers it refuses the connection.
Below is my compose file, indentation might have got spooky during the copy pasta hopefully not.
I had to switch ports from 6379 to 7000 for redis because it was giving me connection problems as well.

version: '3.7'
networks:
  app-tier:
    driver: bridge

services:
 redis:
  image: 'redislabs/rejson:latest'
  command: ["redis-server", "--bind", "redis", "--port", "6379", "--requirepass", "password"]
  environment:
    - appendonly
  ports:
    - '7000:6379'
  volumes:
    - redis:/data
  networks:
    - app-tier

 node:
  build: ./tickingServer
  environment:
    TZ: Europe/Rome
  depends_on:
    - redis
  # - mariadb 
  links:
    - "redis"
  # - "mariadb"

  ports:
    - 3000:3000
  restart: always
  networks:
    - app-tier

 wsdaemon:
  build: ./socketServer
  environment:
    TZ: Europe/Rome
  depends_on:
    - redis
  links:
    - "redis"
  volumes:
    - ./logs:/usr/src/websocketdaemon/logs
  ports:
    - 8000:8000
  restart: always
  networks:
    - app-tier
volumes:
  redis:

on my system the both the native port and the 7000 were free and now they correctly result in use from the docker-proxy.
According to the docker networking I’m using as hostname for the connection ‘redis’ as I named the service so. The python testing snippet for the connection is the following:

import log
import configuration
import redis

config = configuration.configuration()
logger = log.Log().get_logger(
     __name__, config['logFolder'], config['logFormat'])


redis_client = redis.Redis(host='redis', port=7000, db=0, password='password')

the nodejs connector looks like this:

var Redis = require('ioredis');
var logger = require('../helpers/logHelper');
var JSONCache = require('redis-json');


let modName = "RedisConnector";

var redis = new Redis({
  'host': 'redis',
  'family': 4,
  'db': 0,
  'port': 7000,
  'password': 'password'
});

2

Answers


  1. Chosen as BEST ANSWER

    I've managed to connect to redis from another container on the 6379 port instead of the 7000 despite mapping it as such, in the compose file.

    I had to load a redis.conf file and I had to comment out the

    bind 127.0.0.1 
    

    Switch off the protected-mode

    protected-mode no
    

    I had to remove all the keys from the default config that were malformed one by one manually.

    Now, I'm running into the same issue while I'm trying to use the pubsub to propagate channel changes from a websocket python implementation using the rejson library.

    Naturally code snippets from the official documentation channel don't actually work. I've been regretting using redis everyday to save and propagate counting data and I really hope I'll never have to use it again


  2. Ultimately I solved it refactoring the config file down to this settings:

    loadmodule /usr/lib/redis/modules/rejson.so 
    
    protected-mode no
    
    port 6379
    
    timeout 0
    
    tcp-keepalive 300
    
    loglevel notice
    
    logfile ""
    
    databases 4
    
    always-show-logo yes
    
    save 900 1
    
    save 300 10
    
    save 60 10000
    
    dbfilename dump.rdb
    
    appendonly yes
    
    appendfilename "appendonly.aof"
    

    which is still probably just a stub and absurd amount of work to setup a development environment.

    The service definition in the docker-compose file now looks as follows.

    redis:
      image: 'redislabs/rejson:latest'
      command: ["redis-server",  "/usr/local/etc/redis/redis.conf", "--bind", "redis", "--port", "6379", "--requirepass", "password", "--appendonly", "yes"]
    
    
      ports:
        - '7000:6379'
    
      volumes:
        - redis:/data
        - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
      networks:
        - app-tier
    
    volumes:
      redis:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search