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­plic­a­tions.

Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres

Ad­vant­ages of running Redis in Docker

  • Fast de­ploy­ment thanks to pre-con­figured images
  • Port­ab­il­ity across different en­vir­on­ments
  • Easy scaling and auto­ma­tion with Docker Compose or Kuber­netes
  • Good isolation for de­vel­op­ment, testing, and pro­duc­tion en­vir­on­ments
  • Easy in­teg­ra­tion into mi­croservice ar­chi­tec­tures

Pre­requis­ites

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­sist­ently:

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­ately.

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­lessly in­teg­rated with backend services, mi­croservices, 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­tern­ally but also ex­tern­ally (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­ur­a­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­tic­a­tion (requirepass), memory limits, or rep­lic­a­tion.

Redis Docker setup with Docker Compose

For larger projects, it is re­com­men­ded to use Docker Compose:

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

Start your en­vir­on­ment with:

docker compose up -d
bash

Best practices for Redis Docker server

  • Enable re­quire­pass to secure your Redis instance
  • Use TLS/SSL for encrypted com­mu­nic­a­tion
  • Store data in Docker volumes for per­sist­ent storage
  • Monitor con­tain­ers with docker logs, Redis CLI, or mon­it­or­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­ur­a­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