Docker 上安装Redis

1. 在docker仓库中搜索mysql的镜像

  1. docker pull redis

2. 创建配置文件

  1. mkdir -p /mydata/redis/conf
  2. touch /mydata/redis/conf/redis.conf

注意目录层次结构

3.启动容器

  1. docker run -p 6379:6379 --name redis \
  2. -v /mydata/redis/data:/data \
  3. -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
  4. -d redis redis-server /etc/redis/redis.conf

4. 运行 redis

  1. docker exec -it redis redis-cli

5. 开启 aof 持久化

  1. vi /mydata/redis/conf/redis.conf
  2. # 添加如下内容
  3. appendonly yes

6. 随Docker 启动

  1. docker update redis --restart=always

image.png

7.重启

  1. docker restart redis

8.测试

image.png