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
相关推荐
名字还没想好☜18 小时前
用 systemd 托管后台服务:Restart 策略、日志接管、资源限制与开机自启全踩一遍
运维·docker·kubernetes
动力 continue19 小时前
docker容器大舞台,创建镜像,构造类,基础速通
docker·容器
Akiyama_Mio-Kon19 小时前
2026 最新:Dify 本地 Docker 部署完整教程(Windows + Git Bash)
windows·git·docker
野熊佩骑1 天前
Kubernetes实战系列文章(三) 之 K8S运维常用命令
linux·运维·docker·微服务·云原生·容器·kubernetes
一个向上的运维者1 天前
Kubernetes 网络三部曲:CNI、kube-proxy 与 CoreDNS 是如何协作的?
网络·容器·kubernetes
DolitD1 天前
实时云渲染多应用并发:CELL容器技术突破3D隔离瓶颈
云原生·容器·实时互动·图形渲染·数据可视化
鹤落晴春1 天前
【K8s】Kustomize管理
云原生·容器·kubernetes
石小千1 天前
Docker 笔记(九)--离线安装
docker·容器
dazhong20121 天前
Docker 进阶篇(二) Docker Compose 部署 Nginx 实践
nginx·docker·容器
码--到成功1 天前
Docker、Kubernetes安装系列 一
docker·容器·kubernetes