Docker 安装Reids,有图有步骤,这一篇就够了
https://hub.docker.com/_/redis
1、下载Redis镜像
[root@huawei_p20-8301b9330f1b93 conf]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
7d63c13d9b9b: Pull complete
a2c3b174c5ad: Pull complete
283a10257b0f: Pull complete
7a08c63a873a: Pull complete
0531663a7f55: Pull complete
9bf50efb265c: Pull complete
Digest: sha256:f6002442cb71e9d0a40d3640485adbcb68979ad2dcae099e3aae7b8e18cfe1c6
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
2、Dockers启动Redis
创建文件目录和文件
[root@huawei_p20-8301b9330f1b93 conf]# mkdir -p /mydata/redis/conf
[root@huawei_p20-8301b9330f1b93 conf]# touch /mydata/redis/conf/redis.conf
3、启动Redis
docker run -p 6379:6379 --name redis \
-v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf
参数解释
- -p 6379:6379:将容器的6379端口映射到主机的6379端口
- –name:给容器命名
- -v : 挂载宿主机目录和 docker容器中的目录,前面是宿主机目录(Linux目录),后面是容器内部目录
- -d : 后台运行容器
4、Redis持久化(aof)
编辑文件按i,编辑完了按Esc,然后按wq保存,如果不保存按q!,后面都是编辑文件都是一样的操作
[root@huawei_p20-8301b9330f1b93 //]# vi /mydata/redis/conf/redis.conf
redis.conf配置文件,直接复制即可
appendonly yes
重启Redis生效
[root@huawei_p20-8301b9330f1b93 //]# docker restart redis
redis
5、 测试
[root@huawei_p20-8301b9330f1b93 //]# docker exec -it redis redis-cli
127.0.0.1:6379> set a v1
OK
127.0.0.1:6379> get a
"v1"
127.0.0.1:6379> exit
可以看图片重启后值能获取
6、Redis的配置文件
这个里面有Redis的配置文件,需要看哪个可以找对应版本
https://redis.io/topics/config