docker-redis-cluster

docker-redis-cluster

Docker化Redis集群:快速部署与测试环境

docker-redis-cluster项目提供了一个预配置的Redis集群Docker镜像。该镜像默认部署6个Redis实例,构建了3主3从的集群架构。支持最新Redis版本,并允许自定义节点数量和添加Sentinel。这个项目主要用于快速搭建演示、开发和测试环境,不建议用于生产。通过简单的Docker命令,开发者可以轻松管理Redis集群,加速学习和开发过程。项目还支持IPv6和多版本Redis构建,增强了使用灵活性。

DockerRedis集群容器化数据库Github开源项目

docker-redis-cluster

Docker Stars Docker Pulls Build Status

Docker image with redis built and installed from source and a cluster is built.

To find all redis-server releases see them here https://github.com/antirez/redis/releases

Discussions, help, guides

Github have recently released their Discussions feature into beta for more repositories across the github space. This feature is enabled on this repo since a while back.

Becuase we now have this feature, the issues feature will NOT be a place where you can now ask general questions or need simple help with this repo and what it provides.

What can you expect to find in there?

  • A place where you can freely ask any question regarding this repo.
  • Ask questions like how do i do X?
  • General help with problems with this repo
  • Guides written by me or any other contributer with useful examples and ansers to commonly asked questions and how to resolve thos problems.
  • Approved answers to questions marked and promoted by me if help is provided by the community regarding some questions

What this repo and container IS

This repo exists as a resource to make it quick and simple to get a redis cluster up and running with no fuzz or issues with mininal effort. The primary use for this container is to get a cluster up and running in no time that you can use for demo/presentation/development. It is not intended or built for anything else.

I also aim to have every single release of redis that supports a cluster available for use so you can run the exact version you want.

I personally use this to develop redis cluster client code https://github.com/Grokzen/redis-py-cluster

What this repo and container IS NOT

This container that i have built is not supposed to be some kind of production container or one that is used within any environment other than running locally on your machine. It is not ment to be run on kubernetes or in any other prod/stage/test/dev environment as a fully working commponent in that environment. If that works for you and your use-case then awesome. But this container will not change to fit any other primary solution than to be used locally on your machine.

If you are looking for something else or some production quality or kubernetes compatible solution then you are looking in the wrong repo. There is other projects or forks of this repo that is compatible for that situation/solution.

For all other purposes other than what has been stated you are free to fork and/or rebuild this container using it as a template for what you need.

Redis major version support and docker.hub availability

Starting from 2020-04-01 this repo will only support and make available on docker.hub all minor versions in the latest 3 major versions of redis-server software. At this date the tags on docker.hub for major versions 3.0, 3.2 & 4.0, 5.0 will be removed and only 6.0, 6.2, 7.0 will be available to download. This do not mean that you will not be able to build your desired version from this repo but there is no guarantees or support or hacks that will support this out of the box.

Moving forward when a new major release is shipped out, at the first minor release X.Y.1 version of the next major release, all tags from the last supported major version will be removed from docker.hub. This will give some time for the community to adapt and move forward in the versions before the older major version is removed from docker.hub.

This major version schema support follows the same major version support that redis itself use.

Redis instances inside the container

The cluster is 6 redis instances running with 3 master & 3 slaves, one slave for each master. They run on ports 7000 to 7005.

If the flag -e "SENTINEL=true" is passed there are 3 Sentinel nodes running on ports 5000 to 5002 matching cluster's master instances.

This image requires at least Docker version 1.10 but the latest version is recommended.

Important for Mac users

If you are using this container to run a redis cluster on your mac computer, then you need to configure the container to use another IP address for cluster discovery as it can't use the default discovery IP that is hardcoded into the container.

If you are using the docker-compose file to build the container, then you must export a environment variable on your machine before building the container.

# This will make redis do cluster discovery and bind all nodes to ip 127.0.0.1 internally

export REDIS_CLUSTER_IP=0.0.0.0

If you are downloading the container from dockerhub, you must add the internal IP environment variable to your docker run command.

docker run -e "IP=0.0.0.0" -p 7000-7005:7000-7005 grokzen/redis-cluster:latest

Usage

This git repo is using invoke to pull, build, push docker images. You can use it to build your own images if you like.

The invoke scripts in this repo is written only for python 3.7 and above

Install invoke with pip install invoke.

This script will run N num of cpu - 1 parralell tasks based on your version input.

To see available commands run invoke -l in the root folder of this repo. Example

(tmp-615229a94c330b9) ➜  docker-redis-cluster git:(invoke) ✗ invoke -l
"Configured multiprocess pool size: 3
Available tasks:

  build
  list
  pull
  push

Each command is only taking one required positional argument version. Example:

(tmp-615229a94c330b9) ➜  docker-redis-cluster git:(invoke) ✗ invoke build 7.0
...

and it will run the build step on all versions that starts with 6.0.

The only other optional usefull argument is --cpu=N and it will set how many paralell processes will be used. By default you will use n - 1 number of cpu cores that is available on your system. Commands like pull and push aare not very cpu intensive so using a higher number here might speed things up if you have good network bandwidth.

Makefile (legacy)

Makefile still has a few docker-compose commands that can be used

To build your own image run:

make build

To run the container run:

make up

To stop the container run:

make down

To connect to your cluster you can use the redis-cli tool:

redis-cli -c -p 7000

Or the built redis-cli tool inside the container that will connect to the cluster inside the container

make cli

Include sentinel instances

Sentinel instances is not enabled by default.

If running with plain docker send in -e SENTINEL=true.

When running with docker-compose set the environment variable on your system REDIS_USE_SENTINEL=true and start your container.

version: '2'
services:
  redis-cluster:
    ...
  environment:
    SENTINEL: 'true'

Change number of nodes

Be default, it is going to launch 3 masters with 1 slave per master. This is configurable through a number of environment variables:

Environment variableDefault
INITIAL_PORT7000
MASTERS3
SLAVES_PER_MASTER1

Therefore, the total number of nodes (NODES) is going to be $MASTERS * ( $SLAVES_PER_MASTER + 1 ) and ports are going to range from $INITIAL_PORT to $INITIAL_PORT + NODES - 1.

At the docker-compose provided by this repository, ports 7000-7050 are already mapped to the hosts'. Either if you need more than 50 nodes in total or if you need to change the initial port number, you should override those values.

Also note that the number of sentinels (if enabled) is the same as the number of masters. The docker-compose file already maps ports 5000-5010 by default. You should also override those values if you have more than 10 masters.

version: '2'
services:
  redis-cluster:
    ...
  environment:
    INITIAL_PORT: 9000,
    MASTERS: 2,
    SLAVES_PER_MASTER: 2

IPv6 support

By default, redis instances will bind and accept requests from any IPv4 network. This is configurable by an environment variable that specifies which address a redis instance will bind to. By using the IPv6 variant :: as counterpart to IPv4s 0.0.0.0 an IPv6 cluster can be created.

Environment variableDefault
BIND_ADDRESS0.0.0.0

Note that Docker also needs to be configured for IPv6 support. Unfortunately Docker does not handle IPv6 NAT so, when acceptable, --network host can be used.

# Example using plain docker
docker run -e "IP=::1" -e "BIND_ADDRESS=::" --network host grokzen/redis-cluster:latest

Build alternative redis versions

For a release to be buildable it needs to be present at this url: http://download.redis.io/releases/

docker build

To build a different redis version use the argument --build-arg argument.

# Example plain docker
docker build --build-arg redis_version=6.0.11 -t grokzen/redis-cluster .

docker-compose

To build a different redis version use the --build-arg argument.

# Example docker-compose
docker-compose build --build-arg "redis_version=6.0.11" redis-cluster

Available tags

The following tags with pre-built images is available on docker-hub.

Latest release in the most recent stable branch will be used as latest version.

  • latest == 7.2.5

Redis 7.4-rc1 version:

  • 7.4-rc1

Redis 7.2.x version:

  • 7.2.5
  • 7.2.4
  • 7.2.3
  • 7.2.2
  • 7.2.1
  • 7.2.0

Redis 7.0.x version:

  • 7.0.15
  • 7.0.14
  • 7.0.13
  • 7.0.12
  • 7.0.11
  • 7.0.10
  • 7.0.9
  • 7.0.8
  • 7.0.7
  • 7.0.6
  • 7.0.5
  • 7.0.4
  • 7.0.3
  • 7.0.2
  • 7.0.1
  • 7.0.0

Redis 6.2.x versions:

  • 6.2.14
  • 6.2.13
  • 6.2.12
  • 6.2.11
  • 6.2.10
  • 6.2.9
  • 6.2.8
  • 6.2.7
  • 6.2.6
  • 6.2.5
  • 6.2.4
  • 6.2.3
  • 6.2.2
  • 6.2.1
  • 6.2.0

Redis 6.0.x versions:

  • 6.0.20
  • 6.0.19
  • 6.0.18
  • 6.0.17
  • 6.0.16
  • 6.0.15
  • 6.0.14
  • 6.0.13
  • 6.0.12
  • 6.0.11
  • 6.0.10
  • 6.0.9
  • 6.0.8
  • 6.0.7
  • 6.0.6
  • 6.0.5
  • 6.0.4
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 6.0.0

Unavailable major versions

The following major versions is no longer available to be downloaded from docker.hub. You can still build and run them directly from this repo.

  • 5.0
  • 4.0
  • 3.2
  • 3.0

License

This repo is using the MIT LICENSE.

You can find it in the file LICENSE

编辑推荐精选

蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI助手AI工具AI写作工具AI辅助写作蛙蛙写作学术助手办公助手营销助手
Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

热门AI工具生产力协作转型TraeAI IDE
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

聊天机器人AI助手热门AI工具AI对话
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

热门AI工具AI办公办公工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

模型训练热门AI工具内容创作智能问答AI开发讯飞星火大模型多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

AI助手热门AI工具AI创作AI辅助写作讯飞绘文内容运营个性化文章多平台分发
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

下拉加载更多