1.创建目录,并赋予权限
data, logs, conf
mkdir {data,logs,conf}
chmod -R 777 /opt/develop/redis
2.切换到conf目录下,从网上下载redis配置文件
wget http://download.redis.io/redis-stable/redis.conf
3.修改配置文件
# 开启远程连接
bind 0.0.0.0
tcp-backlog 511
timeout 0
tcp-keepalive 300
supervised no
loglevel notice
databases 16
always-show-logo yes
save ""
requirepass your_redis_password
# 开启aof模式
appendonly yes
maxmemory 500mb
maxmemory-policy volatile-lru
protected-mode yes
4.编写docker-compose.yml文件
version: '3.3'
services:
redis:
container_name: redis
image: redis:6.0.6
restart: 'no'
ports:
- 6379:6379
privileged: true
command: redis-server /etc/redis/redis.conf --appendonly yes
volumes:
- $PWD/data:/data:rw
- $PWD/conf/redis.conf:/etc/redis/redis.conf:rw