redis
8.2
sh
mkdir conf datash
docker run --rm \
-v $(pwd)/conf:/tmp/conf \
redis:8.2-alpine \
bash -c "cp /usr/local/etc/redis/redis.conf /tmp/conf/redis.conf"确保 redis.conf 开启了这些
sh
# 持久化
appendonly yes
appendfilename "appendonly.aof"
# 内存限制,避免爆内存
maxmemory 1gb
maxmemory-policy allkeys-lru
# redis stream 相关
stream-node-max-entries 500vim .envsh
REDIS_PASSWORD=卡车123yml
networks:
use-external-net:
external: true # 使用外部网络
name: nginx-proxy-net
services:
redis:
image: redis:8.2-alpine # 最新稳定版本
container_name: redis-prod
networks:
- use-external-net
restart: unless-stopped
env_file: .env
command: redis-server /usr/local/etc/redis/redis.conf --requirepass ${REDIS_PASSWORD} --dir /data
ports:
- "6379:6379" # 可根据需要修改
volumes:
- ./data:/data
- ./conf/redis.conf:/usr/local/etc/redis/redis.conf # 可自定义更多参数如果挂 volumes 就添加:
volumes:
redis_data: