Redis is an open-source in-memory data store used as a cache, message broker, and primary database for low-latency workloads. This guide deploys Redis using Docker Compose with both RDB snapshots and AOF persistence enabled, password authentication, and a tuned host kernel setting. By the end, you'll have Redis accepting authenticated clients on your server.
Set Up the Directory Structure
1. Create the project directory structure:
$ mkdir -p ~/redis-stack/{data,conf}
$ cd ~/redis-stack
2. Create the environment file:
$ nano .env
REDIS_PASSWORD=STRONG_REDIS_PASSWORD
REDIS_PORT=6379
3. Create the Redis configuration file:
$ nano conf/redis.conf
bind 0.0.0.0
protected-mode yes
port 6379
save 900 1
save 300 10
save 60 10000
dir /data
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
Prepare the Host
Redis recommends vm.overcommit_memory=1 to avoid background-save failures under memory pressure.
1. Append the sysctl setting:
$ echo "vm.overcommit_memory = 1" | sudo tee -a /etc/sysctl.conf
2. Apply it immediately:
$ sudo sysctl -p
Deploy with Docker Compose
1. Create the Docker Compose manifest:
$ nano docker-compose.yaml
services:
redis:
image: redis:7.2
container_name: redis
command: [
"redis-server",
"/usr/local/etc/redis/redis.conf",
"--requirepass", "${REDIS_PASSWORD}"
]
ports:
- "${REDIS_PORT}:6379"
volumes:
- "./data:/data"
- "./conf/redis.conf:/usr/local/etc/redis/redis.conf:ro"
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD}
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "PING"]
interval: 10s
timeout: 3s
retries: 5
start_period: 5s
2. Start the service:
$ docker compose up -d
3. Verify the service is running:
$ docker compose ps
$ docker compose logs
Verify Connectivity
1. Install the redis-cli tool:
$ sudo apt install redis-tools -y
2. Ping the server with the password:
$ redis-cli -h REDIS_HOST -p REDIS_PORT -a REDIS_PASSWORD PING
A PONG response confirms Redis is accepting authenticated clients.
Next Steps
Redis is running with persistence and password auth. From here you can:
- Tune
maxmemoryand the eviction policy to match your workload - Configure replication (
replicaof) for read scaling and warm standbys - Bind Redis to
127.0.0.1and front it via a VPN or stunnel for remote access
For the full guide with additional tips, visit the original article on Vultr Docs.
Top comments (0)