So, In the last post, we seen. How to install the Redis server on a Linux machine. Let’s discuss the easiest way of setting up the Redis Docker server using the Docker container.
I don’t know about you guys, but I love Dockers a lot. It expedites and simplifies processes. Using a Docker container, we’ll install the Redis server image. Compared to installing it in Windows or Linux, it is a lot simpler and easier.
Redis Docker Image
- Registered Account with Docker Hub.
- Docker Engine running on any of the OS(Linux, Windows, Mac).
- Credentials already configured with Docker Engine to download the image from the Docker hub.
Install Docker Container as One-time Activity
The following link will help you to set up the docker in your machine. https://docs.docker.com/engine/install
Connect to Host Machine
I have a docker container up and running in my CentOs 7 virtual machine. So, lets start by accessing the VM using the ssh client.
Once connected to the Linux machine. I have already installed the docker engine on my machine.
Search Redis Docker Image in Docker Hub
If you are not sure about the Redis server image. Not a problem. Just open the Docker hub and search for the image which you want to install.
You should also see a similar search result. Just click on the first result is. It will redirect you to the detailed page of Redis
As you can see on the detailed page. the command is already listed which can be used to install the Redis server.
Pull Redis Docker Image By Issuing the Command
docker run --name myredis -d redis
Once you are done with the installation. Issue docker ps command to see the running instance of Redis.
docker ps -a
As we can see our Redis container image is up and running. so, let’s try to connect to the Redis server with our Redis-CLI tool.
Redis-CLI tool in Docker
As we have seen in earlier installation guides, Redis-CLI can be run directly to the machine where the Redis server is running. But, in this case, it’s a bit different.
sudo docker exec -it myredis redis-cli ping
if the executed command is successful then you would see the response message “PONG” from the Redis server.
That’s it! You are done with the installation of the Redis server on the docker container. You can start consuming the Redis server using varieties of languages like C#, Python, and Node Js.