bashbeginner

Redis Docker Setup with Persistence

Docker Compose for Redis with persistence, password auth, memory limits, and a health check.

bash
# 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 10

Use 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.