拉取镜像
docker pull redis:6.0.6
查看镜像
docker images
查看一下镜像已经拉下来了
下载配置文件
到redis官网下载一下压缩包, www.redis.cn/download.ht...

解压一下,把这个文件准备好

然后修改redis.conf
- bind 127.0.0.1 # 注释掉这部分,否则只能本地访问
- protected-mode no # 不开启保护模式,否则只能本地访问
创建两个文件夹
一个是用来放配置文件的,一个是用来放数据文件的
bash
mkdir -p redis/conf
mkdir -p redis/data
配置文件上传到文件夹中

启动redis
bash
docker run -p 6666:6379 --name jackxuredis -v /redis/conf/redis.conf:/etc/redis/redis.conf -v /redis/data:/data -d redis:6.0.6 redis-server /etc/redis/redis.conf --appendonly yes
-p 6666:6379
:把容器内的6379端口映射到宿主机6666端口
--name jackxuredis
:给容器起名字
-v /redis/conf/redis.conf:/etc/redis/redis.conf
:把宿主机配置好的redis.conf放到容器内的这个位置中
-v /redis/data:/data
:把redis持久化的数据在宿主机内显示,做数据备份
-d redis:6.0.6
:表示后台启动redis
redis-server /etc/redis/redis.conf
:这个是关键配置,让redis不是无配置启动,而是加载容器内的conf文件,最终加载的是宿主机上的文件。 重要: 配置文件映射,docker镜像redis 默认无配置文件。
--appendonly yes
:redis启动后数据持久化

查看运行成功
docker ps
已经在运行了
进入redis客户端
bash
docker exec -it jackxuredis redis-cli
可以执行命令了
远程连接测试


至此就全部安装完毕了,小伙伴们快去试试吧~