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
相关推荐
武子康2 小时前
Java-193 Spymemcached 深入解析:线程模型、Sharding 与序列化实践全拆解
java·开发语言·redis·缓存·系统架构·memcached·guava
yuguo.im3 小时前
Docker 两大基石:Namespace 和 Cgroups
运维·docker·容器
会飞的土拨鼠呀3 小时前
docker部署 outline(栗子云笔记)
笔记·docker·容器
Jelly-小丑鱼4 小时前
Linux搭建syslog日志服务器
linux·服务器·docker·日志服务器·syslog服务器
没有bug.的程序员4 小时前
高频IO服务优化实战指南
java·jvm·spring·容器
weixin_462446234 小时前
一键修复 Redis + OpenVAS 权限和启动问题
数据库·redis·bootstrap
lisanmengmeng5 小时前
docker 方式安装部署禅道zentao(五)
运维·docker·容器
程序员老赵6 小时前
AdguardHome Docker 容器化部署指南
docker·dns
露临霜7 小时前
Docker安装nginx
nginx·docker·容器
CAFEBABE 349 小时前
安装完docker之后怎么使用
运维·docker·容器