1. 创建挂载文件目录
mkdir -p /home/redis/config
mkdir -p /home/redis/data
touch /home/redis/config/redis.conf
2. 书写配置文件
port 6379
requirepass youpassword
appendonly yes
appendfsync everysec
appendfilename "appendonly.aof"
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
maxmemory 2gb
maxmemory-policy allkeys-lru
3. 拉取镜像文件
docker pull redis:7.0.2
4. 启动容器
docker run -p 6379:6379 \
--name redis \
-v /home/redis/config/redis.conf:/etc/redis/redis.conf \
-v /home/redis/data:/data \
-d redis:7.0.2 redis-server \
/etc/redis/redis.conf --appendonly yes