搭建Redis7 Docker环境 so easy
准备工作
在docker中搭建一个单机版本的Redis7.2.5环境,前期准备如下:
- 一台安装了docker的linux机器
- Redis7.2.5版本镜像和redis.conf配置文件
- redis镜像:
上面的镜像可以从https://hub.docker.com镜像仓库中进行查找,如下图所示:
命令如下:
docker pull redis:7.2.5-alpine
- 需要修改redis.conf:
#bind 127.0.0.1 -::1
#关闭保护模式
protected-mode no
#开启rdb
save 3600 1 300 100 60 10000
#指定密码
requirepass {密码}
#开启aof
appendonly yes
#开启混合持久模式
aof-use-rdb-preamble yes
配置文件可以从redis官方网站下载:
https://raw.githubusercontent.com/redis/redis/7.2/redis.conf
- 创建数据目录和配置文件
mkdir -p /home/ubuntu/apps/redis/data
- 将修改后的redis.conf上传到/home/ubuntu/apps/redis目录
安装redis
命令如下:
docker run --restart=always --name redis \
-p 6379:6379 \
-v /home/ubuntu/apps/redis/data:/data \
-v /home/ubuntu/apps/redis/redis.conf:/etc/redis/redis.conf \
-d redis:7.2.5-alpine redis-server /etc/redis/redis.conf
查看是否安装成功:
docker ps