Files
chill_notes/Docker/Docker安装redis.md
2026-04-21 17:41:25 +08:00

17 lines
1.5 KiB
Markdown
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**Docker安装redis**
**1.首先下载redis镜像**
docker pull redis
**2.然后创建一个文件夹用来存放redis的配置文件、数据等(也就是所谓的挂载目录,作用就是将此目录中的文件或文件夹覆盖掉容器内部的文件或文件夹)**
**3.在上面创建的目录下使用命令启动redis容器**
docker run -d -p 6379:6379 -v $PWD/conf/redis.conf:/usr/local/etc/redis/redis.conf -v $PWD/data:/data --name docker-redis docker.io/redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
**解释一下上面命令的意义:**
-d表示后台运行不加-d执行上面的命令你就会看到redis启动的日志信息了
-p表示端口映射冒号左面的是我们的宿主机的端口也就是我们虚拟机的端口而右侧则表示的是mysql容器内的端口
--name是我们给redis容器取的名字
-v表示挂载路径$PWD表示当前目录下冒号左面的表示我们宿主机的挂载目录也就是我们虚拟机所在的文件路径冒号右边则表是的是redis容器在容器内部的路径上面的命令我分别挂载了redis.conf(redis的配置文件)如需使用配置文件的方式启动redis这里则需要加上还有redis存放数据所在的目录
--appendonly yes表示redis开启持久化策略
作者GatHub
链接https://www.jianshu.com/p/2f95680f21c5
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。