docker 安装 redis

拉取最新的Redis镜像

powershell 复制代码
docker pull redis:7.0.2

mkdir -p /home/tools/redis/{conf,data}

启动一个临时Redis容器

powershell 复制代码
docker run -d --name redis-temp redis:7.0.2

将容器内的默认配置文件复制到宿主机

powershell 复制代码
docker cp redis-temp:/usr/local/etc/redis/redis.conf /home/tools/redis/conf/

如果复制不到

powershell 复制代码
安装  wget
sudo yum install wget

# 下载 Redis 7.0.2 的默认配置文件
wget https://raw.githubusercontent.com/redis/redis/7.0.2/redis.conf -O /home/tools/redis/conf/redis.conf

停止并删除临时容器

powershell 复制代码
docker rm -f redis-temp

配置文件修改

powershell 复制代码
# 注释掉这行,允许远程连接(或者改为 bind 0.0.0.0)
# bind 127.0.0.1 -::1
bind 0.0.0.0
# 关闭保护模式,允许远程连接
protected-mode no

# 设置访问密码(务必修改为一个强密码)
requirepass 123456

# 开启AOF持久化
appendonly yes

# 设置日志级别
loglevel notice

运行 Redis 容器:

powershell 复制代码
docker run -d \
  --name redis \
  -p 6379:6379 \
  -v /home/tools/redis/conf/redis.conf:/etc/redis/redis.conf \
  -v /home/tools/redis/data:/data \
  redis:7.0.2 \
  redis-server /etc/redis/redis.conf
相关推荐
栗子~~14 小时前
JAVA - 二层缓存设计(本地缓冲+redis缓冲+广播所有本地缓冲失效) demo
java·redis·缓存
Mr. zhihao18 小时前
深入解析redis基本数据结构
数据结构·数据库·redis
仙柒41519 小时前
Docker存储原理
运维·docker·容器
柿柿快乐20 小时前
Redis 入门第一课:全局命令、内部编码与单线程模型
redis·学习·缓存·基础教学
快乐的哈士奇1 天前
LangFuse 自托管实战:选型理由、Docker 部署与常用配置全解析
运维·人工智能·docker·容器
Tirzano1 天前
超大型组和用户缓存redis
redis·缓存·哈希算法
阿维的博客日记1 天前
zset实现延迟队列
redis·zset
无小道1 天前
Redis——string类型相关指令
redis·指令·string
weixin_449290011 天前
Docker + MySQL 在 Windows 11 上的本地安装部署文档
mysql·docker·容器
Ysn07191 天前
中文乱码:在 Docker 容器中设置中文语言环境
运维·python·docker·容器