1 安装redis
docker pull redis:版本 # 如 docker pull redis:6
2 创建数据和配置文件夹
# 配置文件夹
/opt/docker/redis/conf
# 数据文件夹
/opt/docker/redis/data
2 下载redis对应版本的配置文件
一般情况下,每个大版本的配置文件是通用的。地址如下:
# 7.0
https://raw.githubusercontent.com/redis/redis/7.0/redis.conf
# 6.2
https://raw.githubusercontent.com/redis/redis/6.2/redis.conf
# 6
https://raw.githubusercontent.com/redis/redis/6.0/redis.conf
3 修改配置文件中的配置
# 修改密码
requirepass 123456
5 执行如下命令
docker run --restart=always -p 6379:6379 --name=redis -v /opt/docker/redis/conf/redis.conf:/etc/redis/redis.conf -v /opt/docker/redis/data:/data -d redis:6.2 redis-server /etc/redis/redis.conf
注意:
1 配置文件和redis版本最好能一致,不然启动会出错。