Redis is among the most popular Docker images and is often used as a lightning-fast in-memory database, func­tion­ing as a cache, session store, or message broker. In this article, we show you step-by-step how to use Redis with Docker and connect it with other Docker con­tain­ers or external ap­pli­ca­tions.

Dedicated Servers
Per­for­mance through in­no­va­tion
  • Dedicated en­ter­prise hardware
  • Con­fig­urable hardware equipment
  • ISO-certified data centers

Ad­van­tages of running Redis in Docker

  • Fast de­ploy­ment thanks to pre-con­fig­ured images
  • Porta­bil­i­ty across different en­vi­ron­ments
  • Easy scaling and au­toma­tion with Docker Compose or Ku­ber­netes
  • Good isolation for de­vel­op­ment, testing, and pro­duc­tion en­vi­ron­ments
  • Easy in­te­gra­tion into mi­croser­vice ar­chi­tec­tures

Pre­req­ui­sites

To use Redis in Docker, you need:

Step 1: Start Redis Docker Container

Use the following command to start a basic Redis Docker container that stores its data per­sis­tent­ly:

sudo docker run --name my-redis-container -d redis
bash

The official Redis image from Docker Hub uses port 6379 by default and is ready to use im­me­di­ate­ly.

Step 2: Connect Redis Docker instance container to container

Use a custom network to connect your Docker Redis server instance with other con­tain­ers:

docker network create redis-net
docker run --name my-redis-container --network redis-net -d redis
docker run --name my-redis-client --network redis-net -it redis redis-cli -h my-redis-container
bash

This allows Redis to be seam­less­ly in­te­grat­ed with backend services, mi­croser­vices, or admin tools without using the outdated –link option.

Step 3: Allow external access to Redis Docker Container

If you want to use Redis not only in­ter­nal­ly but also ex­ter­nal­ly (e.g., via a remote server), enable port for­ward­ing:

docker run --name my-redis-container -p 7001:6379 -d redis
bash

Access from the client:

redis-cli -h [host-IP or domain] -p 7001
bash
Note

Open the port in your firewall and secure your instance with a password in the redis.conf.

Step 4: Use custom redis.conf in the container

You can provide your own con­fig­u­ra­tion for the Docker Redis server:

docker run --name my-redis-container \
    -v /data/myredis/redis.conf:/usr/local/etc/redis/redis.conf \
    redis redis-server /usr/local/etc/redis/redis.conf
bash

This allows for custom settings such as au­then­ti­ca­tion (requirepass), memory limits, or repli­ca­tion.

Redis Docker setup with Docker Compose

For larger projects, it is rec­om­mend­ed to use Docker Compose:

version: '3'
services:
    redis:
        image: redis
        ports:
            - "6379:6379"
        volumes:
            - redis-data:/data
volumes:
    redis-data:
bash

Start your en­vi­ron­ment with:

docker compose up -d
bash

Best practices for Redis Docker server

  • Enable re­quirepass to secure your Redis instance
  • Use TLS/SSL for encrypted com­mu­ni­ca­tion
  • Store data in Docker volumes for per­sis­tent storage
  • Monitor con­tain­ers with docker logs, Redis CLI, or mon­i­tor­ing tools
  • Keep Redis and Docker images regularly updated

Con­clu­sion

A Redis Docker container can be set up in a matter of minutes and is ideal for local de­vel­op­ment and pro­duc­tion in­fra­struc­tures. Thanks to the official Redis image, clear net­work­ing concepts, and easy con­fig­u­ra­tion, Redis can quickly connect with other Docker con­tain­ers and operate securely. With Docker Compose, your own redis.conf, and best practices, you can get the most out of your setup.

Go to Main Menu