Docker is a containerization platform that allows you to develop, package, and ship applications in standalone environments. It enables developers to create application environments that run anywhere with all the tools and required dependencies.
We will learn how to run Redis in a container using Docker for this one.
In this tutorial, we assume you have the latest version of Docker installed on your system. If not, you can check the resources below to learn how to accomplish this.
Once you have Docker installed and configured on your system, we can proceed with the tutorial.
Step 1 – Start the Docker Service
The first step is to enable and start the docker service. If you use Docker desktop on Windows, Linux or macOS, run the application to start the service.
You can also use the command as shown below:
To check the status of the Docker service, enter the command:
Step 2 – Get Docker image
The next step is to pull the docker image from the official docker hub. We can do this by running the command:
Step 3 – Start Redis Container
To start the Docker container, run the command shown below:
The command above should run the docker container with the Redis server.
You can check the status of the docker image using the ps command as:
The command above should return an example output as shown:
Test if Redis Server is Up
To test if the Redis server is up and running, open the terminal and run the command:
The command above gives you a shell session to your docker container.
Run the command above to test the connection to the Redis server
If you get the output as PONG, the server is up.
You can then connect to the Redis CLI using the command:
Step 4 – Stop Docker Container
Once you perform your database operations, you can stop the redis container using the command:
This short article discusses building and a Redis server instance on Docker. We hope you enjoyed the tutorial.
Check other linuxhint tutorials to learn more.