Redis Docker Setup with Persistence
Docker Compose for Redis with persistence, password auth, memory limits, and a health check.
# docker-compose.redis.yml
version: '3.8'
services:
redis:
image: redis:7-alpine
command: redis-server /usr/local/etc/redis/redis.conf
ports:
- '6379:6379'
volumes:
- redis-data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf:ro
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 10s
timeout: 5s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 256M
volumes:
redis-data:
# redis.conf
# requirepass your_strong_password
# maxmemory 200mb
# maxmemory-policy allkeys-lru
# appendonly yes
# appendfsync everysec
# save 900 1
# save 300 10Use Cases
- Local Redis instance for development
- Session store for web applications
- Caching layer with data persistence
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Redis Cache Get/Set Helper
Type-safe Redis cache wrapper with automatic JSON serialization, TTL support, and cache-aside pattern.
Docker Compose Multi-Service Setup
Docker Compose configuration for a Node.js app with PostgreSQL, Redis, and Nginx reverse proxy.
PostgreSQL Docker Setup with Init Script
Docker Compose for PostgreSQL with volume persistence, init scripts, and connection pooling.
Dockerfile Multi-Stage Build
Multi-stage Dockerfile for Node.js with build, prune, and minimal production image layers.