My objective is to set up 3x Redis Server and 3x Redis Sentinel on a single Docker VM using Docker compose and expose each of the Redis Servers and Sentinels to the local network.
The static IP of my Docker host is 192.168.2.90.
I've given the Redis Servers ports numbered 6379, 6380, 6381 and exposed those ports through Docker.
My local network is 192.168.2.0/24
My Docker machine's internal network is 172.16.0.0/12.
Everything works great within the Docker containers themselves. The problem comes when I try to connect to Redis using a different machine on my local network.
My python test script successfully connects to Redis Sentinel. The problem is when it discovers the master and slaves, the addresses are all on the 172.16.0.0/12 subnet.
Redis master:
('172.18.3.1', 6379)
Redis slaves:
[('172.18.3.3', 6381), ('192.168.2.90', 6379),('172.18.3.2', 6380)]
When I telnet into the master and run INFO, likewise it gives me the 172.16.0.0/12 addresses.
role:master
connected_slaves:2
slave0:ip=172.18.3.3,port=6381,state=online,offset=252692195,lag=0
slave1:ip=172.18.3.2,port=6380,state=online,offset=252692195,lag=0
I cannot figure out how to get Redis Server and Redis Sentinel to report the 192.168.2.0/24 subnet.
I've defined my Redis Server containers as follows:
redis-a-1:
container_name: redis-a-1
hostname: redis-a-1
image: redis
command: "redis-server --port 6379 --bind-source-addr 192.168.2.90"
environment:
- REDIS_HOST=192.168.2.90
ports:
- "6379:6379"
restart: unless-stopped
networks:
blue-green-network:
ipv4_address: 172.18.3.1
redis-a-2:
container_name: redis-a-2
hostname: redis-a-2
image: redis
command: "redis-server --port 6380 --bind-source-addr 192.168.2.90 --slaveof 192.168.2.90 6379"
environment:
- REDIS_HOST=192.168.2.90
ports:
- "6380:6380"
restart: unless-stopped
networks:
blue-green-network:
ipv4_address: 172.18.3.2
redis-a-3:
container_name: redis-a-3
hostname: redis-a-3
image: redis
command: "redis-server --port 6381 --bind-source-addr 192.168.2.90 --slaveof 192.168.2.90 6379"
environment:
- REDIS_HOST=192.168.2.90
ports:
- "6381:6381"
restart: unless-stopped
networks:
blue-green-network:
ipv4_address: 172.18.3.3
I've tried a bunch of things to get each of the Redis Servers to report their IP addresses to each other as the Docker host's IP address but with no success.
Any thoughts on how I can do this or am I on a fool's erand?
Many thanks.
Note: I am aware that the machine itself is a single point of failure.