Skip to content
Sniptide

Docker Compose Redis

This Compose file runs Redis 8 with a password, append-only persistence in a named volume, a 256 MB memory limit and a health check other services can wait on. Save it as compose.yaml, run docker compose up -d --wait, and connect at redis://:dev@127.0.0.1:6379.

Updated

Files

compose.yamlRaw
services:
  redis:
    image: redis:8-alpine
    restart: unless-stopped
    command:
      - redis-server
      - --requirepass
      - ${REDIS_PASSWORD:-dev}
      - --appendonly
      - "yes"
      - --maxmemory
      - 256mb
      - --maxmemory-policy
      - allkeys-lru
    environment:
      # redis-cli reads the password from this variable, so the health check can authenticate.
      REDISCLI_AUTH: ${REDIS_PASSWORD:-dev}
    ports:
      - "127.0.0.1:6379:6379"
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10

volumes:
  redis-data:

Save with your agent

Run this command to add Sniptide to Claude Code in the current project. Open /mcp in Claude Code and sign in to Sniptide. Once the server shows as connected, use the prompt below to save a private copy in your library.

Terminal
claude mcp add --scope local --transport http sniptide https://app.sniptide.com/api/mcp
Prompt
Read https://sniptide.com/templates/docker-compose-redis.json and use create_snippet to save its files as a private Sniptide snippet titled "Docker Compose Redis". Keep the file names and contents from the JSON.

Run it

Use Docker with Compose v2. Run these commands from the folder that holds compose.yaml:

Terminal
docker compose up -d --wait
docker compose exec redis redis-cli ping

The second command prints PONG. From the host, connect with redis://:dev@127.0.0.1:6379. The dev password is a local default. Set REDIS_PASSWORD in a .env file next to compose.yaml before you use it anywhere else, and update the URL to match.

docker compose down stops Redis and keeps the data. Adding -v deletes the volume too.

What each part does

Line
What it does
When to change it
image: redis:8-alpine
Pins the major version.
When you upgrade. Read the release notes for a new major first.
--requirepass
Requires a password from every client. ${REDIS_PASSWORD:-dev} reads .env and falls back to dev.
Always set a real value outside your laptop.
--appendonly yes
Writes every change to a log in /data, so data survives a restart.
Remove it for a pure cache you can lose.
--maxmemory and --maxmemory-policy
Caps memory at 256 MB and evicts the least recently used keys when full.
Use noeviction when Redis holds queues or sessions you can't drop, and size the limit to your data.
REDISCLI_AUTH
Gives redis-cli the password inside the container, for the health check and exec.
Rarely.
ports
127.0.0.1:6379:6379 publishes the port to your machine only.
Change the first 6379 if the port is taken.
healthcheck
Reports healthy once Redis answers PING.
Rarely. Other services wait on it, as the next variant shows.

Variant: with your app

The app reaches Redis by its service name, redis, over the Compose network. Redis needs no published port here.

compose.yaml
services:
  app:
    build: .
    environment:
      REDIS_URL: redis://:${REDIS_PASSWORD:-dev}@redis:6379/0
    ports:
      - "3000:3000"
    depends_on:
      redis:
        condition: service_healthy

  redis:
    image: redis:8-alpine
    command: ["redis-server", "--requirepass", "${REDIS_PASSWORD:-dev}", "--appendonly", "yes"]
    environment:
      REDISCLI_AUTH: ${REDIS_PASSWORD:-dev}
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10

volumes:
  redis-data:

Variant: with Redis Insight

Redis Insight is a browser UI for looking at keys. Add it under services, run docker compose up -d --wait, open http://localhost:5540 and add a database with host redis, port 6379 and your password.

compose.yaml
  redis-insight:
    image: redis/redisinsight:latest
    ports:
      - "127.0.0.1:5540:5540"
    depends_on:
      redis:
        condition: service_healthy
All templates
  • Docker and deployDocker Compose Postgres

    A Docker Compose file for Postgres with a persistent volume, a health check and optional init scripts, plus variants with an app service and pgAdmin.

  • Docker and deployPython Dockerfile with uv

    A multi-stage Python Dockerfile that installs dependencies with uv from a lockfile, caches them between builds and runs the app as a non-root user.

  • .env
    Project setup.env.example template

    A .env.example template with grouped variables, safe defaults and empty secrets, plus how to keep it in sync with your code and share the real values.

Pick where your library lives.

Use sniptide.com

Save your first pattern in the app, then connect Claude Code, Cursor or Codex with one sign-in in the browser.

Run it on your own server

One image and a database give you the app, the API and the MCP endpoint. Sniptide is open source under AGPL-3.0.

$docker compose up -d