我正在尝试使用docker与Redis Sentinel 3.2.11建立Spring启动应用程序。但是我得到了
引起:io.netty.channel.ConnectTimeoutException:连接超时:/172.27.0.2:6379
我的docker撰写配置
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文件
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"]
application.properties中的Spring配置:
redis.cluster.name=mymaster
redis.sentinel.nodes=localhost:26379
redis.timeout=2000
问题:
spring boot app(从docker-machine外部运行)能够与Sentinel节点连接。前哨节点向主信息提供IP 172.27.0.2,即docker n / w IP。 spring boot app尝试在IP 172.27.0.2上与redis-master连接并失败,因为在docker机器外部看不到IP。
可能的解决方法:
如何让Sentinel节点提供主IP作为localhost而不是内部docker-machine n / w ip?