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
相关推荐
容器魔方5 小时前
Bloomberg 正式加入 Karmada 用户组!
云原生·容器·云计算
christine-rr10 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
muyun280010 小时前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
Nazi611 小时前
k8s的dashboard
云原生·容器·kubernetes
凯子坚持 c11 小时前
精通 Redis list:使用 redis-plus-plus 的现代 C++ 实践深度解析
c++·redis·list
weixin_4569042711 小时前
跨域(CORS)和缓存中间件(Redis)深度解析
redis·缓存·中间件
波波烤鸭12 小时前
Redis 高可用实战源码解析(Sentinel + Cluster 整合应用)
数据库·redis·sentinel
傻傻虎虎15 小时前
【Docker】常用帮忙、镜像、容器、其他命令合集(2)
运维·docker·容器
是小崔啊15 小时前
叩丁狼K8s - 概念篇
云原生·容器·kubernetes
MarkHard12320 小时前
如何利用redis使用一个滑动窗口限流
数据库·redis·缓存