Docker安装Redis挂载配置全过程
作者:Pole丶逐
本篇文章介绍了创建挂载文件目录、书写配置文件、拉取镜像文件和启动容器的步骤,个人经验分享,希望大家参考支持
1. 创建挂载文件目录
mkdir -p /home/redis/config mkdir -p /home/redis/data # 设置目录权限 sudo chmod -R 777 /home/redis # 创建配置文件:docker容器中默认不包含配置文件 vim /home/redis/config/redis.conf
2. 书写配置文件
# 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. 拉取镜像文件
docker pull redis:7.0.2
4. 启动容器
docker run -p 6379:6379 \ --name redis \ -v /home/redis/config/redis.conf:/etc/redis/redis.conf \ -v /home/redis/data:/data \ --restart=unless-stopped \ -d redis:7.0.2 redis-server \ /etc/redis/redis.conf --appendonly yes
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
