bitnami / containers

Bitnami container images
https://bitnami.com
Other
3.03k stars 4.38k forks source link

[bitnami/redis-cluster] After changing portmapping, redis-cluster doesnot work #67138

Closed bryanxtong closed 1 day ago

bryanxtong commented 1 month ago

Name and Version

bitnami/redis-cluster:7.2

What architecture are you using?

amd64

What steps will reproduce the bug?

With different port mapping, It gives different results and when using all the default redis port 6379 for container, It is working but It doesnot work when using different redis port in different containers, please refer to attached for full files which includes the correct and wrong file, the only difference is the port mapping.

---It is working----

version: '3'
services:
  redis-node-0:
    user: root
    container_name: redis-node-0
    image: docker.io/bitnami/redis-cluster:7.2
    ports:
      - 6379:6379
      - 16379:16379
    volumes:
      - ./redis_data-0:/bitnami/redis/data
    environment:
      - 'ALLOW_EMPTY_PASSWORD=yes'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
      - 'REDIS_CLUSTER_DYNAMIC_IPS=no'
      - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.71.4'
      - 'REDIS_CLUSTER_ANNOUNCE_PORT=6379'
      - 'REDIS_CLUSTER_ANNOUNCE_BUS_PORT=16379'
    networks:
      redis-cluster-network:
        ipv4_address: 172.20.0.2
.....

---Not working---

version: '3'
services:
  redis-node-0:
    user: root
    container_name: redis-node-0
    image: docker.io/bitnami/redis-cluster:7.2
    ports:
      - 6380:6380
      - 16380:16380
    volumes:
      - ./redis_data-0:/bitnami/redis/data
    environment:
      - 'ALLOW_EMPTY_PASSWORD=yes'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
      - 'REDIS_PORT_NUMBER=6380'
      - 'REDIS_CLUSTER_DYNAMIC_IPS=no'
      - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.71.4'
      - 'REDIS_CLUSTER_ANNOUNCE_PORT=6380'
      - 'REDIS_CLUSTER_ANNOUNCE_BUS_PORT=16380'
    networks:
      redis-cluster-network:
        ipv4_address: 172.20.0.2
....

The error is as below

redis-node-5  | Node redis-node-0 not ready, waiting for all the nodes to be ready...
redis-node-5  | Could not connect to Redis at redis-node-0:6385: Connection refused
redis-node-5  | Node redis-node-0 not ready, waiting for all the nodes to be ready...
redis-node-5  | Could not connect to Redis at redis-node-0:6385: Connection refused
redis-node-5  | Node redis-node-0 not ready, waiting for all the nodes to be ready...
redis-node-5  | Could not connect to Redis at redis-node-0:6385: Connection refused
redis-node-5  | Node redis-node-0 not ready, waiting for all the nodes to be ready...
redis-node-5  | Could not connect to Redis at redis-node-0:6385: Connection refused
redis-node-5  | Node redis-node-0 not ready, waiting for all the nodes to be ready...

What is the expected behavior?

No response

What do you see instead?

It should create redis cluster successfully whatever port mapping we are using

Additional information

No response

bryanxtong commented 1 month ago

docker-compose-redis-cluster.zip docker-compose files

jotamartos commented 1 month ago

Hi @bryanxtong,

I just made a quick test, changed the default port in the cluster using the default docker-compose.yml file

diff --git a/bitnami/redis-cluster/docker-compose.yml b/bitnami/redis-cluster/docker-compose.yml
index 9f17c63b48f..c5d565367be 100644
--- a/bitnami/redis-cluster/docker-compose.yml
+++ b/bitnami/redis-cluster/docker-compose.yml
@@ -10,6 +10,9 @@ services:
     environment:
       - 'REDIS_PASSWORD=bitnami'
       - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
+      - REDIS_PORT_NUMBER=6380
+      - REDIS_MASTER_PORT_NUMBER=6380
+      - REDIS_CLUSTER_ANNOUNCE_PORT=6380

   redis-node-1:
     image: docker.io/bitnami/redis-cluster:7.2
@@ -18,6 +21,9 @@ services:
     environment:
       - 'REDIS_PASSWORD=bitnami'
       - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
+      - REDIS_PORT_NUMBER=6380
+      - REDIS_MASTER_PORT_NUMBER=6380
+      - REDIS_CLUSTER_ANNOUNCE_PORT=6380

   redis-node-2:
     image: docker.io/bitnami/redis-cluster:7.2
@@ -26,6 +32,9 @@ services:
     environment:
       - 'REDIS_PASSWORD=bitnami'
       - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
+      - REDIS_PORT_NUMBER=6380
+      - REDIS_MASTER_PORT_NUMBER=6380
+      - REDIS_CLUSTER_ANNOUNCE_PORT=6380

   redis-node-3:
     image: docker.io/bitnami/redis-cluster:7.2
@@ -34,6 +43,9 @@ services:
     environment:
       - 'REDIS_PASSWORD=bitnami'
       - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
+      - REDIS_PORT_NUMBER=6380
+      - REDIS_MASTER_PORT_NUMBER=6380
+      - REDIS_CLUSTER_ANNOUNCE_PORT=6380

   redis-node-4:
     image: docker.io/bitnami/redis-cluster:7.2
@@ -42,6 +54,9 @@ services:
     environment:
       - 'REDIS_PASSWORD=bitnami'
       - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
+      - REDIS_PORT_NUMBER=6380
+      - REDIS_MASTER_PORT_NUMBER=6380
+      - REDIS_CLUSTER_ANNOUNCE_PORT=6380

   redis-node-5:
     image: docker.io/bitnami/redis-cluster:7.2
@@ -59,6 +74,9 @@ services:
       - 'REDIS_CLUSTER_REPLICAS=1'
       - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
       - 'REDIS_CLUSTER_CREATOR=yes'
+      - REDIS_PORT_NUMBER=6380
+      - REDIS_MASTER_PORT_NUMBER=6380
+      - REDIS_CLUSTER_ANNOUNCE_PORT=6380

 volumes:
   redis-cluster_data-0:

and everything worked as expected

# Replication
role:master
connected_slaves:1
slave0:ip=172.20.0.2,port=6380,state=online,offset=280,lag=1

Could you please take a look at this?

bryanxtong commented 1 month ago

Yes, if all the container shares the same port, It works. My problem is that why different ports in different container port doesnot work.

bryanxtong commented 1 month ago

docker-compose-wrong.zip

try this version which different ports are set for different containers

jotamartos commented 1 month ago

Hi @bryanxtong,

I'm afraid that that configuration is not supported in the solution. Would like to contribute? You can follow our contributing guidelines and improve the solution based on your needs. Our team will be more than happy to review the changes.

However, I also offer you a "solution", why don't you use the default configuration (port 6379) and expose each container using a different port in the host machine using the ports field? Would that work for you?

bryanxtong commented 1 month ago

Once I used others docker compose for testing redis cluster with different ports and then switch to bitnami later. Ok since It is not an issue,you can close it now.

takkyuuplayer commented 3 weeks ago

By configuring the port in REDIS_NODES, I was able to launch the Redis cluster on a different port.

- 'REDIS_NODES=redis-node-0:port0 redis-node-1:port1 redis-node-2:port2 redis-node-3:port3 redis-node-4:port4 redis-node-5:port5'
bryanxtong commented 3 weeks ago

By configuring the port in REDIS_NODES, I was able to launch the Redis cluster on a different port.

- 'REDIS_NODES=redis-node-0:port0 redis-node-1:port1 redis-node-2:port2 redis-node-3:port3 redis-node-4:port4 redis-node-5:port5'

I tried but It doesnot work, please refer to attachment. docker-compose-diff-port.zip

takkyuuplayer commented 3 weeks ago

When you set REDIS_CLUSTER_ANNOUNCE_IP, REDIS_NODES must be

REDIS_NODES=192.168.71.4:6380 ...

The REDIS_NODES items should match the result of redis-cli -c -p 6380 cluster nodes

bryanxtong commented 3 weeks ago

When you set REDIS_CLUSTER_ANNOUNCE_IP, REDIS_NODES must be

REDIS_NODES=192.168.71.4:6380 ...

The REDIS_NODES items should match the result of redis-cli -c -p 6380 cluster nodes

Hi takkyuuplayer,

Thanks for the answer and It is working. I provided the attachment for both hostname(needs hosts file config) and ip for other people who may encounter the same issue and this version supported external access by java.

and now you can help close the ticket.

docker-compose-redis-cluster-working.zip

Br Bryan

jotamartos commented 3 weeks ago

Thanks for providing that useful information @takkyuuplayer. It'll be really helpful for all those users who want to use different ports during the deployment

github-actions[bot] commented 5 days ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.