拉取最新的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