When to use this stack
Redis is an in-memory data store used for caching, sessions, rate limits, job queues and real-time counters. Its commands are simple and fast, and most web frameworks support it out of the box. This stack runs Redis 7 with a password, append-only file persistence, a memory cap and a healthcheck, and adds RedisInsight 2.70, a graphical client for browsing keys, running commands and watching memory and latency. It is a practical setup for a single server that needs a shared cache or queue with an easy way to inspect it.
Use this stack when your application needs a cache or a broker-like structure on the same Compose network, or when you want to inspect Redis data during development and incident response. Do not treat it as a durable primary database unless you have configured persistence and backups carefully, and do not run it without a password. Redis is not designed to be exposed to the internet. Only RedisInsight is published, and only on localhost, so you reach it through an SSH tunnel. Redis itself stays on the internal network.
docker-compose.yml
services:
redis:
image: redis:7-alpine
restart: unless-stopped
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}", "--appendonly", "yes", "--maxmemory", "${REDIS_MAXMEMORY}", "--maxmemory-policy", "allkeys-lru"]
environment:
REDISCLI_AUTH: ${REDIS_PASSWORD}
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
start_period: 5s
redisinsight:
image: redis/redisinsight:2.70.0
restart: unless-stopped
ports:
- "127.0.0.1:5540:5540"
volumes:
- redisinsight_data:/data
depends_on:
redis:
condition: service_healthy
volumes:
redis_data:
redisinsight_data:# Password required by every client of this Redis server
REDIS_PASSWORD=CHANGE_ME_STRONG_REDIS_PASSWORD
# Memory cap for the dataset. Keep it below the container memory limit.
REDIS_MAXMEMORY=256mb.env
# Password required by every client of this Redis server
REDIS_PASSWORD=CHANGE_ME_STRONG_REDIS_PASSWORD
# Memory cap for the dataset. Keep it below the container memory limit.
REDIS_MAXMEMORY=256mbStart and verify
The variables are loaded into the shell for the checks below. Compose reads .env on its own. The REDISCLI_AUTH variable lets redis-cli inside the container authenticate without typing the password on the command line.
set -a; . ./.env; set +a
docker compose config --quiet
docker compose up -d
docker compose ps
docker compose exec redis redis-cli ping
docker compose exec redis redis-cli SET healthcheck:test ok
docker compose exec redis redis-cli GET healthcheck:test
docker compose logs --tail=30 redisinsight
curl -s -o /dev/null -w "RedisInsight HTTP status: %{http_code}\n" http://127.0.0.1:5540/Production checklist
- Replace the CHANGE_ME password with a long random value, and never commit the real .env file to version control.
- Keep port 6379 unpublished. Clients reach Redis through the host name redis on the Compose network.
- Replace the shared password with ACL users, one per application, with only the commands and key patterns each one needs.
- Choose the eviction policy on purpose. allkeys-lru suits a cache, while noeviction suits queues and data that must not disappear.
- Keep AOF enabled for data you cannot rebuild, and monitor disk latency because AOF writes depend on it.
- Track memory fragmentation, latency and slow commands with INFO and SLOWLOG.
- Keep RedisInsight behind an SSH tunnel or a VPN. It has full access to every server it is connected to.
- Pin the image tag and read the release notes before upgrading the major version.
Common problems
-
Symptom: clients fail with NOAUTH Authentication required. Cause: the client does not send the password. Fix: add the password to the client configuration, or use a URL of the form redis://:password@redis:6379 from another container.
-
Symptom: RedisInsight cannot connect to the database. Cause: the host was entered as localhost, which points to RedisInsight itself inside its container. Fix: add the database with host redis, port 6379 and the password from .env.
-
Symptom: Redis logs MISCONF and refuses writes. Cause: the disk is full, or the volume cannot be written by the Redis process. Fix: free disk space, check the volume with docker volume inspect, and restart the service once the disk has room.
-
Symptom: memory keeps growing until the container is killed by the operating system. Cause: maxmemory is not set, or the container limit is lower than the cap. Fix: set REDIS_MAXMEMORY below the container memory limit, and choose an eviction policy that fits the data.
Variations
- Read replica: add a second Redis service that runs with replicaof redis 6379 and the same masterauth password, then point read-heavy clients at it.
- ACL file: mount a users file and start Redis with the aclfile option, so each application has its own user and password.
- Redis-compatible servers: the Valkey project offers a Redis-compatible server. Check its official image tag before you swap it in, and test your client library against it.
Questions
Why is Redis not published to the host?
Applications on the same Compose network reach it as redis:6379. An open cache port on a public server is one of the most common causes of data theft and cryptomining incidents, so the port stays private.
Why does RedisInsight fail when I enter localhost as the host?
Inside the RedisInsight container, localhost refers to the container itself. Add the database with the host name redis and port 6379.
Should I enable AOF persistence?
Enable it when the data cannot be rebuilt from another source, such as queues or session data. For a pure cache that can be refilled, you can disable it to reduce disk writes.
What does maxmemory do?
It caps how much memory Redis uses for data. Combined with an eviction policy, it decides what happens when the cap is reached, so set it below the container memory limit.
Adapt this stack
Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.
Open in builderRelated stacks
ClickHouse 25.8 Analytics Database
Docker Compose stack for ClickHouse 25.8 with a dedicated user, a healthcheck, raised file limits and HTTP and native ports on localhost for analytical queries.
Elasticsearch 8 + Kibana Search Stack
Docker Compose stack for Elasticsearch 8.19 and Kibana 8.19 with security enabled, a persistent volume, a healthcheck and localhost-only ports.
FastAPI + MongoDB 7 + Mongo Express
Docker Compose stack for a Python FastAPI API on MongoDB 7 with authentication, a healthcheck, persistent storage and a protected Mongo Express UI on localhost.
MariaDB 11.4 LTS + Adminer 5
Docker Compose stack with MariaDB 11.4 LTS, a healthcheck, a named volume and Adminer 5 on localhost. A lightweight admin UI for MySQL-compatible databases.
Browse more Databases & Search stacks or the full library.