---
title: How to Deploy Redis® – In-Memory Data Store
url: https://docs.vultr.com/how-to-deploy-redis-in-memory-data-store
description: Deploy Redis® with Docker Compose on Ubuntu 24.04 with persistence and password security.
publish_date: 2025-12-11T21:45:47.127011Z
last_updated: 2025-12-12T12:07:57.609534Z
author: Aashish Chaurasiya
header_image: https://assets.vultrdevrel.com/docs-main-doc-assets-1/2443/c4b435eb-1674-4abd-9e36-15f5c11e2616.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Redis® is an in-memory data store designed for low-latency access, supporting strings, lists, sets, sorted sets, streams, and pub/sub messaging. It is commonly used as a cache layer, message broker, and lightweight in-memory key-value database for high-throughput applications.

This article explains how to deploy Redis® with Docker Compose, enable data persistence, and secure it with a password.

## Prerequisites

Before you begin, you need to:

* Have access to an [Ubuntu 24.04-based server](https://www.vultr.com/servers/ubuntu/) as a [non-root user with `sudo` privileges](https://docs.vultr.com/limited-user-login).
* Install [Docker and Docker Compose](https://docs.vultr.com/how-to-install-docker-on-ubuntu-24-04).

## Set Up the Directory Structure and Environment Variables

In this section, you create a project directory for Redis® and define environment variables in a `.env` file that Docker Compose loads automatically.

1. Create the project directory.

    ```console
    $ mkdir -p ~/redis-stack/{data,conf}
    ```

1. Navigate into the project directory.

    ```console
    $ cd ~/redis-stack
    ```

1. Create a `.env` file to store the environment variables.

    ```console
    $ nano .env
    ```

    Add the following variables:

    ```ini
    REDIS_PASSWORD=STRONG_REDIS_PASSWORD
    REDIS_PORT=6379
    ```

    Replace:

    * `STRONG_REDIS_PASSWORD` with a secure alphanumeric password.
    * `REDIS_PORT` with your preferred port (default: `6379`).

    Save and close the file.

1. Create a Redis® configuration file.

    ```console
    $ nano conf/redis.conf
    ```

    Add the following Redis settings:

    ```ini
    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"
    ```

    Save and close the file.

## Prepare the Host System for Redis®

In this section, you configure the host system to support reliable Redis® operations. Redis® requires memory overcommit to be enabled. Without this setting, background save operations or replication may fail, and the container may exit unexpectedly.

1. Open the /etc/sysctl.conf file.

    ```console
    $ sudo nano /etc/sysctl.conf
    ```

    Add the following line to enable memory overcommit.

    ```ini
    vm.overcommit_memory = 1
    ```

    Save and close the file.

1. Apply the updated kernel parameters.

    ```console
    $ sudo sysctl -p
    ```

    Output:

    ```
    vm.overcommit_memory = 1
    ```

    This output confirms that the memory overcommit setting is active on your system.

## Deploy with Docker Compose

In this section, you create the Docker Compose manifest that deploys Redis® with data persistence, loads your custom configuration file, and secures the server using a password defined in your `.env` file.

1. Create the Docker Compose manifest.

    ```console
    $ nano docker-compose.yaml
    ```

    Add the following content:

    ```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
    ```

    Save and close the file.

    In this manifest:

    * **services**: Defines the containers managed by Docker Compose:
        * **redis**: Runs the Redis® server with persistence enabled and password authentication enforced.
    * **image**: Specifies the Redis® 7.2 container image.
    * **container_name**: Assigns a fixed container name for easier management.
    * **command**: Starts Redis® using your custom configuration file and applies the password using the `--requirepass` directive.
    * **ports**: Maps the container’s default Redis® port (`6379`) to the host using the value from your `.env` file.
    * **volumes**:
        * `./data` persists Redis® data across container restarts.
        * `./conf/redis.conf` injects your custom Redis® configuration file into the container.
    * **environment**: Exposes the Redis® password to the container runtime.
    * **healthcheck**: Monitors container health by running a password-authenticated `PING` every 10 seconds.
    * **restart: unless-stopped**: Ensures Redis® automatically restarts unless manually stopped.

1. Start the Redis® service.

    ```console
    $ docker compose up -d
    ```

1. Verify that Redis® is running.

    ```console
    $ docker compose ps
    ```

    Ensure that the output shows the Redis® container is healthy and running.

1. View logs if needed.

    ```console
    $ docker compose logs
    ```

    For more information on managing a Docker Compose stack, see the [How To Use Docker Compose](https://docs.vultr.com/how-to-use-docker-compose) article.

## Verify Redis® Connectivity

In this section, you verify that your Redis® instance is reachable and accepting authenticated commands.

1. Install the Redis® CLI tool on the host.

    ```console
    $ sudo apt install redis-tools -y
    ```

1. Test the connection by sending an authenticated `PING` command.

    ```console
    $ redis-cli -h REDIS_HOST -p REDIS_PORT -a REDIS_PASSWORD PING
    ```

    Replace:

    * `REDIS_HOST` with the IP address of your server.
    * `REDIS_PORT` with the Redis® service port you configured.
    * `REDIS_PASSWORD` with the password you set for authentication.

    Output:

    ```
    PONG
    ```

    This confirms that Redis® is running, reachable, and correctly secured with your password.

## Conclusion

You successfully deployed Redis® using Docker Compose with data persistence and password authentication. You configured the required environment variables, applied the necessary host settings, and launched Redis® with a custom configuration file. After verifying the container’s health and testing connectivity, the Redis® instance was fully operational and ready to use.
