I have a rest api application and redis container in the same compose file. The rest api is a basic application which cache data in to redis cluster . When I got the cotainer up the rest api is not able to communicate to redis cluster. I always get the no reachable node cluster exception
below is the sample of my compose file.
version: ‘2’
services:
redis-cluster:
environment:
IP: ${REDIS_CLUSTER_IP}
build:
context: .
args:
redis_version: ‘4.0.10’
hostname: server
ports:
- ‘7000-7007:7000-7007’
expose:
- ‘7000’
- ‘7001’
- ‘7002’
- ‘7003’
- ‘7004’
- ‘7005’
test-local:
build:
context: ./dockertest
dockerfile: Dockerfile
ports:
- “9090:9090”
links:
- redis-cluster
can somebody help out why I am not able to connect/whats the issue between two containers and I used redis-cluster in my config of rest api application to connect to redis cluster. I pinged from shell of rest api container to redis_cluster and it works.
I did some experimenting with this and ultimately used a modified version of the docker-compose file such that it runs in Swarm. If you haven’t already done so, it’s super simple to enable Swarm on docker for mac: docker swarm init. The benefit being that you get to use overlay networks rather the legacy “link” method.
Since I didn’t have a dockerized application handy in which I could make calls to the redis-cluster, I just used the redis image and its included redis-cli (which will exit and keep restarting after each call). This works out ok because it takes a bit for the redis cluster itself to be fully running anyway, as you can see from the logs of the redis service below:
$ docker service logs -f redis_test
redis_test.1.m8539o9bop9y@linuxkit-025000000001 | Could not connect to Redis at redis-cluster:7000: Connection refused
redis_test.1.9ibh184yl11j@linuxkit-025000000001 | CLUSTERDOWN The cluster is down
redis_test.1.9ibh184yl11j@linuxkit-025000000001 |
redis_test.1.0iwu4n4umev6@linuxkit-025000000001 | 1
redis_test.1.iykziug1jlmy@linuxkit-025000000001 | 2
redis_test.1.tm707iexxzes@linuxkit-025000000001 | 3
redis_test.1.nq3heqkohgvq@linuxkit-025000000001 | 4
redis_test.1.ly1p32u68cf5@linuxkit-025000000001 | 5
One other thing that you probably noticed. I didn’t include the IP environment variable in the redis-cluster service. Looking at the entrypoint for that container, it looks like it will self discover the IPs anyway, which it (obviously) did in my case.