How to Install Redis on Docker in Windows
In this post, I'll walk you through the steps to get Redis up and running in a Docker container on Windows. Redis is a powerful in-memory data structure store, widely used for caching and real-time data storage.
Prerequisites
Before we start, make sure you have the following installed:
-
Docker Desktop for Windows
- Download Docker
- Follow the installation steps and ensure Docker is running on your machine.
-
Windows Subsystem for Linux (WSL) (optional but recommended for a smoother experience)
- Follow Microsoft's guide to install WSL.
Step-by-Step Guide
1. Open Docker Desktop
Once Docker Desktop is installed, open the application and ensure it's running properly. You should see the Docker icon in your system tray.
2. Pull Redis Docker Image
Open your terminal or command prompt and pull the Redis Docker image from Docker Hub by running the following command:
docker pull redis
Docker will download the latest version of Redis. If you want a specific version, you can append the version number like this:
docker pull redis:6.2
3. Run Redis Container
Once the image is pulled, you can create and run a Redis container using the following command:
docker run --name my-redis -p 6379:6379 -d redis
-
--name my-redis
: Assigns a name to the container (you can change my-redis to any name you like). -
-p 6379:6379
: Maps the Redis default port (6379) from the container to your local machine. -
-d
: Runs the container in detached mode, so it runs in the background.
4. Verify Redis is Running
To ensure Redis is up and running, you can check the status of your container:
docker ps
This command will list all running containers, and you should see your my-redis container in the list.
5. Access the Redis CLI
To connect to the Redis instance and access the CLI, use the following command:
docker exec -it my-redis redis-cli
This will open the Redis command-line interface, where you can run commands like:
PING
If everything is set up correctly, you should get a PONG
response.
6. Stop and Remove the Redis Container (Optional)
If you want to stop the Redis container, use:
docker stop my-redis
To remove the container entirely:
docker rm my-redis
Conclusion
Congratulations! 🎉 You've successfully set up Redis on Docker in Windows. Docker makes it incredibly easy to spin up services like Redis without the hassle of manual installation. If you have any questions, feel free to drop a comment below!
Happy coding!
Comments (1)