---
title: 'How to install Redis in Docker and Docker Compose | Zomro'
description: 'In this article, we will discuss how to deploy Redis in Docker and in a Docker Compose file.'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677423608_1.png'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * How to install Redis in Docker and Docker Compose 



# How to install Redis in Docker and Docker Compose

26-02-2023

In this article, we will look at how to deploy Redis in Docker and in the Docker Compose file.  
  
Redis is a high-performance database management system used for storing and processing data in memory. Redis allows for efficient processing of large volumes of data and provides high availability and fault tolerance.  


## **Installing Docker and Docker Compose**

Before we begin, you need to install Docker and Docker Compose. You can find installation instructions for Docker for your operating system on our blog for [Centos 7](https://zomro.com/rus/blog/faq/287-kak-ustanovit-docker-na-centos-7) or for [Ubuntu 20.04](https://zomro.com/rus/blog/faq/286-kak-ustanovit-docker-na-ubuntu-2004).  


###   
**Installing Docker Compose**
    
    
    curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

  
Setting execute permissions. 
    
    
    chmod +x /usr/local/bin/docker-compose

  
Checking the installation of Docker Compose:
    
    
    docker-compose --version

## **Creating Docker Compose file**

To deploy Redis using Docker Compose, we need to create a file **docker-compose.yaml** in the root directory of our project. It will contain the settings for the Redis container.  
  
To keep track of what we have installed in the future, let's create a separate folder for this project in the directory **/home** and navigate to it.
    
    
    mkdir /home/redis && cd /home/redis

  
![How to install Redis in Docker and Docker Compose - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677423608_1.png)  
You can also use another directory**** to place this and other projects.   
  
Let's use the repository to create the file **docker-compose.yaml** at the link <https://hub.docker.com/_/redis>  


### Create a ***.yaml** file for Docker Compose.
    
    
    version: '3.3'
    
    services:
      redis:
        image: redis:latest
        restart: always
        ports:
          - "6379:6379"
        volumes:
          - /path/to/local/dаta:/root/redis
          - /path/to/local/redis.conf:/usr/local/etc/redis/redis.conf
        environment:
          - REDIS_PASSWORD=my-password
          - REDIS_PORT=6379
          - REDIS_DATABASES=16
    

  
  
![How to install Redis in Docker and Docker Compose - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677423579_2.png)  
Let's consider each parameter:  
  
**version** \- this is the version of the Docker Compose file format. We are using version 3.3.  
**services** \- this is the section where we define the list of containers and their settings. In our case, we define one service - Redis.  
**redis** \- this is the name of our service.  
**image** \- this is the name of the Redis image that we will use to create our container.  
**restart** \- this is a setting that tells Docker to restart the Redis container in case of its stoppage or failure.  
**ports** \- this is a setting that defines which ports of the container should be accessible on the host system. In this case, we are forwarding port 6379 of the Redis container to port 6379 of the host system.  
**volumes** \- this is a setting that defines which directories on the host system should be accessible inside the container. In this case, we are mounting directories with Redis data and configuration files.  
**environment** \- this is a setting that allows us to define environment variables for the Redis container. In this case, we define the password, port, and number of Redis databases.  
**REDIS_PASSWORD** : my-password defines the **REDIS_PASSWORD** variable with the value my-password.  
**REDIS_PORT** : **6379** defines the Redis port that will be used in the container. By default, Redis uses port 6379, so this variable can be used to change the port to another if necessary.  
**REDIS_DATABASES: 16** defines the number of Redis databases that will be available in the container. By default, Redis supports 16 databases, but this parameter can be changed using this variable.

## **Running Redis**

Now that we have the **docker-compose.yaml** file, we can start the Redis container using the command:
    
    
    docker-compose up -d

  
![How to install Redis in Docker and Docker Compose - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677423642_3.png)  
This command starts the Redis container in the background (option -d). Docker Compose will automatically download and create the Redis container based on the settings specified in the **docker-compose.yaml** file.  
  
You can check if the Redis container is running by running the command:
    
    
    docker ps | grep redis

  
![How to install Redis in Docker and Docker Compose - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677423668_4.png)  
We can start the Redis container without using the **docker-compose.yaml** file using the following Docker command:
    
    
    docker run -d --name my-redis-container -p 6379:6379 -v /path/to/local/dаta:/root/redis -v /path/to/local/redis.conf:/usr/local/etc/redis/redis.conf -e REDIS_PASSWORD=my-password -e REDIS_PORT=6379 -e REDIS_DATABASES=16 redis:latest
    

**Connecting to Redis**

You can connect to the Redis container using any Redis client. For this, you will need the IP address of your host system and the port that you defined in the **docker-compose.yaml** file.

  
For example, if you are using the standard Redis client, you can connect to the Redis container by running the command:
    
    
    redis-cli -h 172.27.0.2 -p 6379
    

  
![How to install Redis in Docker and Docker Compose - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677423624_5.png)  
Where 172.27.0.2 is the IP address of the Docker container on which Redis is running. To find it, use the command **docker ps | grep redis** to find the ID of our container or use its name.
    
    
    docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis_redis_1

  
![How to install Redis in Docker and Docker Compose - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2023/02/01/1677423618_6.png)  
Where **redis_redis_1** is the name of the container whose IP address needs to be filtered.  
  
This command uses the **\--format** flag to format the output, in which the **range** function is used to iterate over all the container's networks and only the IP address of each network is output. If the container has multiple networks, all their IP addresses will be output. If the container is only connected to one network, only its IP address will be output.  
  
This command **redis-cli -h 172.27.0.2 -p 6379** \- connects to Redis running on the local machine and listening on port **6379**.  
  
To connect from CMS systems, use built-in plugins.   
  
So, in this article, we have looked at how to deploy **Redis** in Docker and Docker Compose. We have created the **docker-compose.yaml** file with settings for the Redis container.

We also suggest you other useful articles:

  * [How to install FileGator file manager in Docker](https://zomro.com/blog/faq/416-how-to-install-filegator-manager-files-in-docker)
  * [How to install MySQL 8 on Docker](https://zomro.com/blog/faq/291-kak-ustanovit-mysql-8-v-docker)
  * [How to install phpMyAdmin in Docker](https://zomro.com/blog/faq/289-kak-ustanovit-phpmyadmin-v-docker)



Similar articles:

[How to create a user and add a domain to the HestiaCP panel?](https://zomro.com/blog/faq/247-kak-sozdat-polzovatelja-i-dobavit-domen-v-panel-hestiacp) [How to install a GUI on Ubuntu and connect to the server via RDP](https://zomro.com/blog/faq/254-kak-ustanovit-graficheskij-interfejs-na-ubuntu-i-podkljuchitsja-k-serveru-po-rdp) [Create an FTP user in Hestia CP and ISPmanager](https://zomro.com/blog/faq/686-create-an-ftp-user-in-hestia-cp-and-isp-manager) [WordPress Multisite: How to create and manage multiple sites from one admin panel](https://zomro.com/blog/faq/322-wordpress-multisite-how-to-create-and-manage-multiple-sites-from-one-admin-panel) [Installation of PostgreSQL and pgAdmin4 on HestiaCP panel](https://zomro.com/blog/faq/326-ustanovka-postgresql-i-pgadmin4-na-panel-hestiacp)

[ GPU server from €174.80/mon ](/dedicated-servers/type=gpu)
