1 redis配置文件
- 官方下载:redis.conf
- 路径:在容器中,一般可以保存在
/etc/redis/redis.conf
路径中 - 配置文件详解,根据实际情况进行修改:
port 6379
daemonize no
protected-mode no
requirepass redis123
databases 16
save 900 1
save 300 10
save 60 10000
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
2 docker命令启动
docker run -p 6379:6379 \
-v /Users/chenbinhao/redis_6379/data:/data \
-v /Users/chenbinhao/redis_6379/config/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf --appendonly yes
- 参数说明
-p
端口映射,redis默认端口为6379-v
主要映射两个路径中的文件
/data
redis容器中会将数据保存在该路径中,此处映射是为了持久化保存数据。/etc/redis/redis.conf
自定义配置文件保存的位置,此处映射是为了启动时可以指定自定义配置文件。
-d
表示在后台以守护进程进行运行。注意:redis.conf配置文件中需要配置daemonize no
,否则无法将无法启动成功。redis-server /etc/redis/redis.conf --appendonly yes
启动redis命令,如果以自定义配置文件启动,则需要执行此命令。
- 日志查看:
docker logs containerID
如果启动失败使用此命令进行查看失败日志,根据日志进行调试
3 docker-compose启动
├─reids_6379
│ ├─docker-compose.yml
│ ├─config
│ │ └─redis.conf
│ └─data
│ │ └─..
version: '3'
services:
redis:
image: redis:latest
restart: always
ports:
- "6379:6379"
volumes:
- "./data:/data"
- "./config/redis.conf:/etc/redis/redis.conf"
command: redis-server /etc/redis/redis.conf
- 启动命令
- 启动:在docker-compose.yml所在目录中执行
docker-compse up -d
- 停止并删除:
docker-compose down