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'
});