0

I am trying to set up a Spring boot application with Redis Sentinel 3.2.11 using docker. However I am getting

Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /172.27.0.2:6379

My docker compose configuration

version: '3.1'
services:
  master:
    image: redis:3
    container_name: redis-master
    hostname: host_dev
    networks:
      - docker_dev
 slave:
   image: redis:3
   command: redis-server --slaveof redis-master 6379
   hostname: host_dev
   links:
    - master:redis-master
   container_name: redis-slave
   networks:
    - docker_dev
 sentinel:
   build: sentinel
   environment:
    - SENTINEL_DOWN_AFTER=5000
    - SENTINEL_FAILOVER=5000
    - MASTER_NAME=mymaster
   hostname: host_dev
   image: sentinel:3
   links:
    - master:redis-master
    - slave
   container_name: sentinel
   ports:
    - "26379:26379"
   networks:
    - docker_dev
networks:
 docker_dev:

Docker file

FROM redis:3

EXPOSE 26379
ADD sentinel.conf /etc/redis/sentinel.conf
RUN chown redis:redis /etc/redis/sentinel.conf
ENV SENTINEL_QUORUM 2
ENV SENTINEL_DOWN_AFTER 30000
ENV SENTINEL_FAILOVER 180000
COPY sentinel-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/sentinel-entrypoint.sh
ENTRYPOINT ["sentinel-entrypoint.sh"]

Spring configuration in application.properties:

redis.cluster.name=mymaster
redis.sentinel.nodes=localhost:26379
redis.timeout=2000

Issue:

The spring boot app(run from outside docker-machine) is able to connect with Sentinel node. The sentinel node provides the master information with IP 172.27.0.2 i.e docker n/w IP. The spring boot app tries to connect with redis-master at IP 172.27.0.2 and fails as the IP is not visible outside the docker machine.

Possible fix:

How can I make sentinel node provide an master IP as localhost instead of internal docker-machine n/w ip?

JDev
  • 1,662
  • 4
  • 25
  • 55
  • Not really a programming question. However the sentinel won't be able to talk to either the master or slave because it's on a different network. If you add a second internal network for the compose that all of them can talk to, then it should work; once you change `MASTER_NAME` to `redis-master` – Anya Shenanigans Feb 20 '18 at 14:26
  • Ah! the missing piece `docker-machine` - at a guess you're on mac or windows, which means that the docker networks are inaccessible to the host. If you want this to work, you need to move the spring boot app into the docker container as well. – Anya Shenanigans Feb 21 '18 at 10:33
  • @Patesh I am on mac and want to run spring-boot from IDE(Eclipse). Deploying the service as Docker is not an option :( – JDev Feb 21 '18 at 14:29
  • This: https://github.com/mal/docker-for-mac-host-bridge might allow you to do this. I've not had any luck myself because of office-internal network address overlap issues. – Anya Shenanigans Feb 22 '18 at 16:12
  • @JDev any luck resolving this issue ? I am also trying to connect a spring boot with Sentinel docker but facing same connectivity issue. – R K Nov 29 '18 at 03:51
  • 1
    @RK I was able to make it work by running the microservice as a docker image and on the same n/w i.e docker_dev – JDev Dec 10 '18 at 16:59

0 Answers0