1、docker-comose
version: '3'
services:
redis: # 服务名称
image: redis:6.0.10 # redis镜像版本
container_name: redis # 容器名称
ports:
- 6379:6379 # 指定宿主机端口与容器端口映射关系,宿主机:容器
volumes:
- ./config/redis.conf:/etc/redis/redis.conf # 映射配置文件目录,宿主机:容器
- ./data:/data # 映射数据目录,宿主机:容器
restart: always # 容器开机自启
#privileged: true # 获取宿主机root权限
command: ["redis-server","/etc/redis/redis.conf"] # 指定配置文件启动redis-server进程 2、创建文件夹
mkdir -p config data3、编写redis配置文件./config/redis.conf
# 关闭保护模式,允许远程连接
protected-mode no
# 开启AOF持久化
appendonly yes
# 密码
requirepass redis123456.4、启动
docker-compose up -d