How to use Redis in Docker Containers
Redis is among the most popular Docker images and is often used as a lightning-fast in-memory database, functioning 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 containers or external applications.
- Dedicated enterprise hardware
- Configurable hardware equipment
- ISO-certified data centers
Advantages of running Redis in Docker
- Fast deployment thanks to pre-configured images
- Portability across different environments
- Easy scaling and automation with Docker Compose or Kubernetes
- Good isolation for development, testing, and production environments
- Easy integration into microservice architectures
Prerequisites
To use Redis in Docker, you need:
- A Linux server with Docker installation (e.g., Ubuntu 24.04, Debian 12, or AlmaLinux 9)
- Basic knowledge of using the command line
- Optional: Access without
sudo, by membership in the Docker group
Step 1: Start Redis Docker Container
Use the following command to start a basic Redis Docker container that stores its data persistently:
sudo docker run --name my-redis-container -d redisbashThe official Redis image from Docker Hub uses port 6379 by default and is ready to use immediately.
Step 2: Connect Redis Docker instance container to container
Use a custom network to connect your Docker Redis server instance with other containers:
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-containerbashThis allows Redis to be seamlessly integrated with backend services, microservices, or admin tools without using the outdated –link option.
- Secures data transfers
- Avoids browser warnings
- Improves your Google ranking
Step 3: Allow external access to Redis Docker Container
If you want to use Redis not only internally but also externally (e.g., via a remote server), enable port forwarding:
docker run --name my-redis-container -p 7001:6379 -d redisbashAccess from the client:
redis-cli -h [host-IP or domain] -p 7001bashOpen 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 configuration 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.confbashThis allows for custom settings such as authentication (requirepass), memory limits, or replication.
Redis Docker setup with Docker Compose
For larger projects, it is recommended to use Docker Compose:
version: '3'
services:
redis:
image: redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
volumes:
redis-data:bashStart your environment with:
docker compose up -dbashBest practices for Redis Docker server
- Enable requirepass to secure your Redis instance
- Use TLS/SSL for encrypted communication
- Store data in Docker volumes for persistent storage
- Monitor containers with docker logs, Redis CLI, or monitoring tools
- Keep Redis and Docker images regularly updated
Conclusion
A Redis Docker container can be set up in a matter of minutes and is ideal for local development and production infrastructures. Thanks to the official Redis image, clear networking concepts, and easy configuration, Redis can quickly connect with other Docker containers and operate securely. With Docker Compose, your own redis.conf, and best practices, you can get the most out of your setup.

