Home / Configs / Containers / docker-compose for Redis

docker-compose for Redis: example file with password and persistence

Run Redis in Docker with a password, saved data and a memory limit.

For Docker Desktop (Windows, macOS) or Docker Engine with the Compose plugin (Linux).

This docker-compose file runs Redis with a password, optional data saving and an optional memory limit. Choose your settings below, then run docker compose up -d and test it with redis-cli.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Click Generate for a strong one
Examples: 128mb, 1gb

docker-compose.yml
services:
  redis:
    image: redis:7
    restart: unless-stopped
    command:
      - redis-server
      - --requirepass
      - change-me-redis
      - --appendonly
      - "yes"
    ports:
      - "6379:6379"
    volumes:
      - redisdata:/data

volumes:
  redisdata:

How this setup works

Diagram: docker compose up, then Redis container, then redisdata volume
docker compose up (one command) → Redis container (your port) → redisdata volume (saved data)

Step-by-step setup

  1. Save the config as docker-compose.yml in an empty folder.
  2. Start it: docker compose up -d.
  3. Test it: redis-cli -h 127.0.0.1 -p 6379 ping. With a password, add -a and your password. The answer PONG means it works.
  4. Read the log if needed: docker compose logs redis.

What the important lines mean

Common errors and how to fix them

NOAUTH Authentication required
The server has a password. Use redis-cli -a yourpassword or put the password in your app’s connection string.
Could not connect to Redis: Connection refused
The container is not running, or you used the wrong port. Check docker compose ps.
Port 6379 is already allocated
Another Redis or container uses it. Pick another port above, such as 6380.
Data is lost after a restart
Save data to disk must be ticked, and the volume must stay. Do not use docker compose down -v.

Frequently asked questions

How do I test that Redis is working?
Run redis-cli ping. The reply PONG means it is running.
Is it safe to expose Redis to the internet?
No. Keep it on localhost or a private network, and always set a password.
What is the difference between a cache and saved data?
A cache can lose keys safely, so use a memory limit. For data you cannot lose, turn on saving to disk and skip the memory limit.

Written for: Docker 27, Compose v2, Redis 7 · Updated 2026-10-03

Free tools that help

Fix a problem with this setup

More container configs

See all 41 config generators