DEV Community

Cover image for Deploying Redis In-Memory Data Store on Ubuntu 24.04
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya • Originally published at docs.vultr.com

Deploying Redis In-Memory Data Store on Ubuntu 24.04

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
Enter fullscreen mode Exit fullscreen mode

2. Create the environment file:

$ nano .env
Enter fullscreen mode Exit fullscreen mode
REDIS_PASSWORD=STRONG_REDIS_PASSWORD
REDIS_PORT=6379
Enter fullscreen mode Exit fullscreen mode

3. Create the Redis configuration file:

$ nano conf/redis.conf
Enter fullscreen mode Exit fullscreen mode
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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

2. Apply it immediately:

$ sudo sysctl -p
Enter fullscreen mode Exit fullscreen mode

Deploy with Docker Compose

1. Create the Docker Compose manifest:

$ nano docker-compose.yaml
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode

2. Start the service:

$ docker compose up -d
Enter fullscreen mode Exit fullscreen mode

3. Verify the service is running:

$ docker compose ps
$ docker compose logs
Enter fullscreen mode Exit fullscreen mode

Verify Connectivity

1. Install the redis-cli tool:

$ sudo apt install redis-tools -y
Enter fullscreen mode Exit fullscreen mode

2. Ping the server with the password:

$ redis-cli -h REDIS_HOST -p REDIS_PORT -a REDIS_PASSWORD PING
Enter fullscreen mode Exit fullscreen mode

A PONG response confirms Redis is accepting authenticated clients.


Next Steps

Redis is running with persistence and password auth. From here you can:

  • Tune maxmemory and the eviction policy to match your workload
  • Configure replication (replicaof) for read scaling and warm standbys
  • Bind Redis to 127.0.0.1 and 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)