How can I install Redis on Docker?

Last updated 02, May 2024

Question

How can I install Redis on Docker?

Answer

Follow the recommendations for installing Redis Community Edition in the documentation. However, we recommend the installation of Redis Stack to gain access to the modeling capabilities using the JSON data type, to have the ability to search and query your data, use Redis as a vector database, as a time series database, resolve problems using the probabilistic data structures, and more.

To install Redis Stack using Docker, follow the steps in the documentation, also reported here.

Install Docker

First, make sure you have Docker installed on your operating system. You can download and install Docker from the official Docker website.

Pull the Redis image

Open a terminal or command prompt and run the following command to pull the Redis Docker image:

docker pull redis/redis-stack-server:latest

This will download the latest Redis image from the Docker Hub.

Run the Redis Stack container

Once the image is downloaded, run the following command to start a Redis container (if the image hasn't been downloaded, the command will perform the download and create the container all at once). At this stage, you can specify the map the server port to a different one (replace 6379:6379 with the desired port, MY_PORT:6379)

docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest

This command creates and starts a container named "my-redis" using the Redis image. The container will run in the background.

Verify the installation

You can check if the Redis container is running by executing the following command:

docker ps

If the container is running, you will see it listed along with other information. That's it! You have now installed Redis Stack using Docker. During container creation, you can connect to the Redis server using the specified Redis port (6379 is the usual default if otherwise specified).

References

Run Redis Stack on Docker