
Setting Up Redis with Docker Compose in 2026
Jonas ScholzRedis is a powerful in-memory data store for caching, queues, sessions, rate limits, and real-time application features. Docker Compose is one of the fastest ways to run Redis locally or on a small server because it keeps the Redis image, password, volume, restart policy, and port mapping in one repeatable file.
In this guide, you'll learn how to set up Redis with Docker Compose using persistence and a password. If you just need a managed deployment path, you can also deploy Redis on Sliplane and skip the manual server setup.
Redis Hosting Decision Matrix
| Route | Best for | Tradeoff |
|---|---|---|
| Docker Compose | Local development, small VPS setups, learning Redis internals | You maintain updates, firewalling, backups, and monitoring |
| Sliplane preset | Production-ish Redis without server setup | Less low-level access than a raw VPS |
| Fully managed Redis provider | Larger teams that need HA, replicas, and vendor support | More expensive and usually more billing complexity |
Redis Docker Compose Setup at a Glance
| Requirement | Recommendation |
|---|---|
| Docker image | redis:7.4-alpine |
| Persistence | Named volume mounted to /data |
| Security | --requirepass with a strong password |
| Restart policy | always for small production services |
| Verification | docker compose exec cache redis-cli -a yourpassword PING |
Step 1: Create a Docker Compose File
First, you'll need to create a Docker Compose file. This file will define the services that make up your application environment. For our purpose, we'll focus on setting up Redis.
Open your text editor and create a file named compose.yml. Here's what you should put in it:
services:
cache:
image: redis:7.4-alpine
restart: always
ports:
- "6379:6379"
command: redis-server --save 20 1 --loglevel warning --requirepass yourpassword
volumes:
- cache:/data
volumes:
cache:
driver: local
Let's break down what each part does:
- services: Defines the services that make up your app. Here, we're defining a service named
cache. You would also add other services here, like a database, a web server, etc. - image: Tells Docker Compose to use the Redis 7.4 image based on Alpine Linux.
- restart: Set to
always, which means the container will restart if it stops or crashes. - ports: Maps port 6379 on your local machine to port 6379 in the container, allowing you to connect to Redis from your host machine.
- command: Customizes the Redis server command.
--save 20 1tells Redis to save the database every 20 seconds if at least one change was made.--loglevel warningsets the logging to show only warnings.--requirepass yourpasswordsets a password for Redis, which is a basic security measure. Replaceyourpasswordwith a strong password. - volumes: Configures a volume named
cacheand maps it to/datainside the container. This ensures that data is persisted even if the container is deleted or recreated.
Step 2: Start the Redis Service
Once your compose.yml file is ready, you can start the Redis service with the following command in your terminal:
docker compose up -d
The -d flag runs the containers in the background. You should see output indicating that the Redis service is up and running.
Step 3: Verify Redis is Running
To ensure Redis is running correctly, you can use the Redis command-line interface (CLI). First, find the name of your Redis container with:
docker compose ps
Then, you can execute the Redis CLI inside the container with:
docker compose exec cache redis-cli -a yourpassword
Replace yourpassword with the password you set in the compose.yml file. Once in the CLI, you can issue commands like PING to check if Redis is responding:
127.0.0.1:6379> PING
PONG
You can also set and get keys to test further:
127.0.0.1:6379> SET testkey "Hello, Redis!"
OK
127.0.0.1:6379> GET testkey
"Hello, Redis!"
Step 4: Stopping and Removing the Redis Service
When you're done, you can stop the Redis service with:
docker compose down
This command will stop and remove the containers defined in your compose.yml file. Your volumes will be preserved!
By following these steps, you've set up Redis with Docker Compose, complete with persistence and basic security. This setup can be easily integrated into larger applications or used standalone for caching purposes.
If you're looking for more information about using Redis with Docker, check out our guide on how to use Redis with Docker. For production deployments and best practices, you might also find our PostgreSQL best practices guide helpful, as many of the same principles apply to Redis.