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
相关推荐
礼拜天没时间.26 分钟前
自定义镜像制作——从Dockerfile到镜像
linux·docker·容器·centos·bash
luffy545936 分钟前
windows下通过docker-desktop创建redis实例
windows·redis·docker·容器
静听山水1 小时前
Redis的Pipeline (管道)
数据库·redis·php
无尽的沉默1 小时前
SpringBoot整合Redis
spring boot·redis·后端
weixin_404679311 小时前
docker部署ollama
运维·docker·容器
静听山水1 小时前
Redis核心数据结构-list
数据结构·redis·list
Hi202402171 小时前
在Docker容器中安全运行OpenClaw:无需虚拟机,体验AI助手
人工智能·安全·docker·openclaw
江湖有缘1 小时前
Docker部署music-tag-web音乐标签编辑器
前端·docker·编辑器
计算机小手1 小时前
Docker 部署 OpenClaw 汉化版,畅玩个人 AI 智能代理
经验分享·docker·aigc·开源软件
Tangcan-2 小时前
【Redis】通用命令 1
数据库·redis·缓存