Docker 安装 Redis 挂载配置

1. 创建挂载文件目录

shell 复制代码
mkdir -p /home/redis/config
mkdir -p /home/redis/data
# 创建配置文件:docker容器中默认不包含配置文件
touch /home/redis/config/redis.conf

2. 书写配置文件

shell 复制代码
# Redis 服务器配置

# 绑定的 IP 地址,默认为本地回环地址 127.0.0.1
# 外网访问需注释掉此行
# bind 127.0.0.1

# 监听的端口,默认为 6379
port 6379

# 设置密码
requirepass youpassword

# 启用 AOF 持久化模式
appendonly yes

# 持久化方式。可选项:always, everysec, no
appendfsync everysec

# AOF 文件名称,默认为 appendonly.aof
appendfilename "appendonly.aof"

# AOF 自动重写触发条件
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

# 设置最大内存限制(单位:字节)
maxmemory 2gb

# 内存淘汰策略。可选项:volatile-lru, allkeys-lru, volatile-random, allkeys-random, volatile-ttl, noeviction
maxmemory-policy allkeys-lru

3. 拉取镜像文件

shell 复制代码
docker pull redis:7.0.2

4. 启动容器

shell 复制代码
docker run -p 6379:6379 \
--name redis \
-v /home/redis/config/redis.conf:/etc/redis/redis.conf \
-v /home/redis/data:/data \
-d redis:7.0.2 redis-server \
/etc/redis/redis.conf --appendonly yes
相关推荐
My_Java_Life14 分钟前
windows中使用docker部署Milvus和Autt
windows·docker·milvus
jran-16 分钟前
Docker 架构&命令
运维·docker·容器
Devin~Y38 分钟前
大厂Java面试实录:Spring Boot/Cloud + Redis + Kafka + JVM + RAG(Spring AI)三轮追问(小Y翻车版)
java·jvm·spring boot·redis·spring cloud·kafka·mybatis
小义_1 小时前
【Kubernetes】(二十)ETCD 备份与恢复
容器·kubernetes·etcd
oddsand11 小时前
原理篇-Redis数据结构
数据库·redis·缓存
zz0723201 小时前
Redis + Lua 实现高性能分布式限流
redis·lua·aop·限流算法·分布式限流
learning-striving2 小时前
华为云欧拉操作系统的服务器实例中手工部署 Docker
linux·运维·服务器·docker·容器·华为云
月落归舟11 小时前
一篇文章了解Redis内存淘汰机制与过期Key清理
数据库·redis·mybatis
phltxy11 小时前
Redis 事务
数据库·redis·缓存
修己xj12 小时前
别再让Docker占满你的硬盘!一篇搞定docker system所有命令
docker