docker 安装 redis
拉取镜像
复制代码
查看镜像
复制代码
查看一下镜像已经拉下来了

下载配置文件
到 redis 官网下载一下压缩包, www.redis.cn/download.ht…

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

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

启动 redis
复制代码
-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 启动后数据持久化

查看运行成功
复制代码
已经在运行了

进入 redis 客户端
复制代码
可以执行命令了

远程连接测试


至此就全部安装完毕了,小伙伴们快去试试吧~
需要 Redis 相关资料,可以点这里领取哦!谢谢大家的阅读与支持!
评论