五分钟使用 Docker-compose搭建 Redis 8.0 中间件
零基础搭建搭建Redis
最牛逼的一套SpringCloudAlibaba微服务实战项目
1. 创建一个名为redis.conf
bind 0.0.0.0
port 6379
timeout 0
loglevel notice
logfile "/var/log/redis/redis-server.log"
databases 16
save ""
appendonly yes
appendfilename "appendonly.aof"
dir "/data"
2. 创建一个docker-compose.yml
powershell
version: '3.8'
services:
redis:
image: redis:8.0 # 使用Redis 8.0镜像
restart: always
ports:
- "6379:6379" # 将容器的6379端口映射到宿主机的6379端口
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf # 挂载配置文件
- redis-data:/data # 挂载数据卷用于持久化数据
command: redis-server /usr/local/etc/redis/redis.conf # 使用配置文件启动Redis服务器
environment:
- REDIS_REPLICATION_MODE=master # 环境变量,根据需要设置
volumes:
redis-data: # 定义数据卷
确保你的docker-compose.yml文件和redis.conf文件位于同一目录下。然后,在终端中运行以下命令来启动Redis服务