docker-compose安装redis

2023-11-02

基于docker-compose快速安装redis

目录

一、目录结构

1、docker-compose.yml

2、redis.conf

二、连接使用


一、目录结构

1、docker-compose.yml

version: '3'
services:
  redis:
    image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8                    # 镜像'redis:6.0.8'
    container_name: redis                                                             # 容器名为'redis'
    restart: unless-stopped                                                                   # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
    command: redis-server /etc/redis/redis.conf --requirepass hcses.com --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置
#    command: redis-server --requirepass 123456 --appendonly yes # 启动redis服务并添加密码为:123456,并开启redis持久化配置
    environment:                        # 设置环境变量,相当于docker run命令中的-e
      TZ: Asia/Shanghai
      LANG: en_US.UTF-8
    volumes:                            # 数据卷挂载路径设置,将本机目录映射到容器目录
      - "./redis/data:/data"
      - "./redis/config/redis.conf:/etc/redis/redis.conf"  # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf`
    ports:                              # 映射端口
      - "6379:6379"

2、redis.conf

# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.

################################## INCLUDES ###################################

# Include one or more other config files here.  This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings.  Include files can include
# other files, so use this wisely.
#
# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf

################################## MODULES #####################################

# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 注释允许外部访问redis
# bind 127.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
# 开启保护模式后,需要 bind ip 或 设置密码
protected-mode yes

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300
daemonize no

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile ""

databases 16

always-show-logo yes

# 900秒内,如果超过1个key被修改,则发起快照保存
save 900 1
# 300秒内,如果超过10个key被修改,则发起快照保存
save 300 10
# 60秒内,如果1万个key被修改,则发起快照保存
save 60 10000


stop-writes-on-bgsave-error yes


rdbcompression yes


rdbchecksum yes

dbfilename dump.rdb


rdb-del-sync-files no


dir ./




replica-serve-stale-data yes



repl-diskless-sync no


repl-diskless-sync-delay 5

repl-diskless-load disabled



repl-disable-tcp-nodelay no




replica-priority 100


# 设置密码
# requirepass 123456



lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no


lazyfree-lazy-user-del no

oom-score-adj no

oom-score-adj-values 0 200 800



appendonly no

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof"



# 每次操作都会立即写入aof文件中
# appendfsync always
# 每秒持久化一次(默认配置)
appendfsync everysec
# 不主动进行同步操作,默认30s一次
# appendfsync no



no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble yes


lua-time-limit 5000


slowlog-log-slower-than 10000


slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""


hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-size -2

list-compress-depth 0

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

stream-node-max-bytes 4096
stream-node-max-entries 100

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

dynamic-hz yes

aof-rewrite-incremental-fsync yes

rdb-save-incremental-fsync yes

jemalloc-bg-thread yes

二、连接使用

为了方便使用,建议下载个Redis Desktop Manager 可视化工具。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

docker-compose安装redis 的相关文章

随机推荐

  • 不均衡数据集采样2——BorderlineSMOTE算法(过采样)

    论文 Borderline SMOTE A New Over Sampling Method in Imbalanced Data Sets Learning https citeseerx ist psu edu viewdoc down
  • 高级JS(堆、栈、作用域、闭包、原型、this指向)

    一 变量的内存分配 基本数据类型 number string boolean undefined null symbol 引用数据类型 object array object function 基本数据类型 都是存放在栈内存中 栈内存空间大
  • 接口测试工具Postman(三)使用postman抓包捕获HTTP请求

    目录 一 捕获HTTP请求 二 代理 一 捕获HTTP请求 Postman提供了轻松查看和捕获应用程序中发送和接收的实际HTTP请求流量的工具 可以在Postman本机应用程序中使用内置代理进行抓包 1 postman内置代理 postma
  • python实现AI井字棋极大极小算法和Alpha-beta算法

    python实现AI井字棋极大极小算法和Alpha beta算法 程序设计思路 主要步骤和代码 对于两个算法流程图 运行结果 程序设计思路 大致思路 井字棋最后的结果无非就是玩家赢 电脑赢和平局三种结果 而最后的结果正对应这整棵棋盘生成树的
  • 辞职后的一些感想

    辞职了 不急着找工作 一直独立开发app 整天码UI取数据填数据 知识得不到沉淀 以前的blog都删了没什么意思 重新开始做个总结 也算个新启程吧
  • 87.el-table翻页后保存前一页所选并再次返回前一页时把数据勾选上

    1 首先给
  • 汇编基础知识

    一 汇编语法 1 GNU 汇编语法适用于所有的架构 并不是 ARM 独享的 GNU 汇编由一系列的语句组成 每行一条语句 每条语句有三个可选部分 如下 label instruction comment label 即标号 表示地址位置 有
  • Python面试数据库

    1 举常见的关系型数据库和非关系型都有那些 关系型 MySQL SQL Server Oracle Sybase DB2 非关系型 Redis MongodDB 2 MySQL常见数据库引擎及比较 InnoDB MyISAM NDB Mem
  • react基础详细介绍(消息订阅-发布机制、ajax请求、路由基础知识)

    一 消息订阅 发布机制 1 工具库 PubSubJS 2 下载 npm i pubsub js save 3 使用 import PubSub from pubsub js 引入 PubSub subscribe delete functi
  • 程序员护眼法

    第一节 按揉耳垂眼穴 脚趾抓地 用双手大拇指和食指的螺纹面捏住耳垂正中的眼穴 其余三指自然并拢弯曲 伴随音乐口令 用大拇 指和食指有节奏地揉捏穴位 同时用双脚全部脚趾做抓地运动 每拍一次 做四个八拍 第二节 按揉太阳穴 刮上眼眶 用双手大拇
  • Qt QComboBox QSS样式设置

    QComboBox 样式表可谓太丰富了 研究了一阵 总结出的记录 QComboBox整体样式 未下拉时 QComboBox的样式 QComboBox border radius 3px padding 1px 18px 1px 3px ba
  • JavaScript 面试题(核心基础类)

    面试题按类型来分 主要涉及到 技术 与 非技术 两大类 今天我们主要讨论的是 技术类 在这个大类别下涉及到的子类别有 移动 PC端布局类 JavaScript 核心基础类 衍生框架类 项目应用类 JavaScript 核心基础类面试题 一
  • mediawiki使用中遇到的两个问题

    1 禁止新用户自行注册 我的wiki版本是1 22 5的 最近想禁用掉用户注册的功能 网上百度了一下都是 在LocalSettings php中加入 Prevent new user registrations wgWhitelistAcc
  • 最小二乘法拟合圆公式推导及其实现

    1 1最小二乘拟合圆介绍与推导 最小二乘法 least squares analysis 是一种数学优化技术 它通过最小化误差的平方和找到一组数据的最佳函数匹配 最小二乘法是用最简的方法求得一些绝对不可知的真值 而令误差平方之和为最小来寻找
  • 在线教育录播视频防下载安全测试 _EduSoho_HLS(m3u8)

    基于测试某录播课平台视频安全性的需求 对平台上的免费视频进行安全测试 看看到底能否较好的防下载 以下为几种常用的视频加密技术 我们这次的测试平台采用的是第二种 第三种方式主要依靠专用播放器来解决数据交到客户端的这一环的安全性 但是专用播放器
  • js递归缓存方法

    方法一 普通递归缓存法 function fn n if isFinite n n gt 0 n Math round n 不是无限数 是否大于0 取整 if n in fn 是否在fn缓存内 if n lt 1 当n 1时 结果为1 re
  • mysql 索引相关,什么时候该使用索引,什么时候不使用

    索引为什么能提高数据访问性能 很多人只知道索引能够提高数据库的性能 但并不是特别了解其原理 其实我们可以用一个生活中的示例来理解 我们让一位不太懂计算机的朋友去图书馆确认一本叫做 MySQL性能调优与架构设计 的书是否在藏 这样对他说 请帮
  • Qt中UDP通信的简单示例

    udp通信分为发送端和接收端 通信步骤可以分为以下 接收端 创建QUdpSocket对象 在 h文件中添加类的前置声明 定义该类的指针 在 cpp的构造函数中定义指向该类的指针 bind 绑定IP和端口 connect 绑定readyRea
  • 深入理解MongoDB高级架构

    一 MongoDB 索引 MongoDB提供了多样性的索引支持 索引信息被保存在 system indexes 中 且默认总是为 id创建索引 它的索引使用基本和 MySQL 等关系型数据库一样 其实可以这样说说 索引是凌驾于数据存储系统之
  • docker-compose安装redis

    基于docker compose快速安装redis 目录 一 目录结构 1 docker compose yml 2 redis conf 二 连接使用 一 目录结构 1 docker compose yml version 3 servi