Windows Docker Desktop + Linux Docker + Native Redis
Redis is an in-memory data store commonly used for:
By default, Redis listens on:
Host: localhost
Port: 6379
Spring Boot Application
|
| localhost:6379
v
+----------------------+
| Redis |
| |
| Port 6379 |
+----------------------+
Docker option:
Spring Boot
|
| localhost:6379
v
Docker
|
v
local-redis container
|
v
Redis 7
Download and install Docker Desktop for Windows.
After installation, restart Windows if requested.
Start Docker Desktop and wait until the Docker Engine is running.
Open PowerShell or Command Prompt.
docker version
You should see both Client and Server information.
docker info
docker pull redis:7
This downloads Redis version 7 from Docker Hub.
docker run -d --name local-redis -p 6379:6379 redis:7
Explanation:
| Option | Meaning |
|---|---|
| docker run | Create and start a new container |
| -d | Run in detached/background mode |
| --name local-redis | Container name |
| -p 6379:6379 | Map Windows host port 6379 to Redis container port 6379 |
| redis:7 | Redis version 7 image |
docker ps
Expected output should contain something similar to:
CONTAINER ID IMAGE STATUS PORTS
xxxxxxx redis:7 Up ... 0.0.0.0:6379->6379/tcp
The important part is:
redis:7
Up
0.0.0.0:6379->6379/tcp
docker exec -it local-redis redis-cli ping
Expected:
PONG
This is one of the most common Docker Redis mistakes.
| Command | Purpose |
|---|---|
docker run |
Create a new container and start it |
docker start |
Start an existing stopped container |
docker stop |
Stop a running container |
docker restart |
Restart an existing container |
docker rm |
Remove a container |
Do NOT execute docker run again.
docker start local-redis
Expected:
local-redis
docker ps
docker exec -it local-redis redis-cli ping
Expected:
PONG
Check all containers:
docker ps -a
If you see:
local-redis redis:7 Exited
Start it:
docker start local-redis
First check:
docker ps -a
Then check Redis logs:
docker logs local-redis
The logs normally reveal configuration, startup, permission, or port-related problems.
You may see:
Conflict. The container name "/local-redis"
is already in use
This means the container already exists.
Do not execute docker run again.
docker start local-redis
You may see:
Bind for 0.0.0.0:6379 failed:
port is already allocated
Check Windows port usage:
netstat -ano | findstr :6379
If another application is using 6379, you can either stop that application or map Redis to another host port.
docker run -d --name local-redis -p 6380:6379 redis:7
In this case Redis is accessed from the Windows host using:
localhost:6380
If you see an error mentioning:
dockerDesktopLinuxEngine
Start Docker Desktop and wait for the Docker Engine to become ready.
Then test:
docker info
You can test whether port 6379 is reachable using PowerShell:
Test-NetConnection localhost -Port 6379
Expected:
TcpTestSucceeded : True
To automatically restart Redis when Docker restarts:
docker update --restart unless-stopped local-redis
Verify:
docker inspect local-redis
This is useful for local development because you don't have to manually start Redis every time Docker Desktop restarts.
docker --version
docker info
docker pull redis:7
docker run -d --name local-redis -p 6379:6379 redis:7
docker ps
docker exec -it local-redis redis-cli ping
Expected:
PONG
docker start local-redis
or:
docker restart local-redis
If Docker is not required, Redis can be installed directly on a Linux machine.
sudo apt update
sudo apt install redis-server -y
sudo systemctl enable redis-server
sudo systemctl start redis-server
sudo systemctl status redis-server
You should see that the service is active/running.
redis-cli ping
Expected:
PONG
sudo systemctl status redis-server
sudo systemctl start redis-server
sudo systemctl restart redis-server
sudo systemctl stop redis-server
sudo systemctl enable redis-server
sudo ss -lntp | grep 6379
Another useful command:
sudo lsof -i :6379
sudo journalctl -u redis-server
docker ps
docker ps -a
docker logs local-redis
docker start local-redis
docker restart local-redis
docker exec -it local-redis redis-cli ping
Connect to Redis:
redis-cli
Test connection:
redis-cli ping
Check Redis information:
redis-cli info
Check server information:
redis-cli info server
Check memory:
redis-cli info memory
Check keys:
redis-cli keys "*"
KEYS * on large production Redis databases
because it can be expensive. It is fine for simple local testing.
Once Redis is running locally on port 6379, configure your Spring Boot application accordingly.
spring.redis.host=localhost
spring.redis.port=6379
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.redis.* properties.
Use the following sequence whenever your Spring Boot application reports:
RedisConnectionFailureException:
Unable to connect to Redis
docker info
docker ps
docker start local-redis
docker ps -a
docker logs local-redis
docker exec -it local-redis redis-cli ping
PONG
Test-NetConnection localhost -Port 6379
After Redis returns PONG and port 6379 is reachable, restart the Spring Boot application.
| Error | Likely Cause | Solution |
|---|---|---|
| Unable to connect to localhost:6379 | Redis is not running | Start Redis container/service |
| dockerDesktopLinuxEngine | Docker Desktop/Engine is not running | Start Docker Desktop |
| container name already in use | Container already exists | Use docker start local-redis |
| container is not running | Redis container is stopped | Use docker start local-redis |
| port is already allocated | Another process uses 6379 | Find/stop process or use another host port |
| redis-cli not found | Redis CLI not installed locally | Use docker exec or install Redis CLI |
| Connection refused | Redis is not listening on expected port | Check service/container and port |
If you want to completely remove the existing local Redis container:
docker stop local-redis
docker rm local-redis
Then create it again:
docker run -d \
--name local-redis \
-p 6379:6379 \
redis:7
On Windows PowerShell, you can use the single-line version:
docker run -d --name local-redis -p 6379:6379 redis:7
| Purpose | Command |
|---|---|
| Check Docker | docker info |
| Running containers | docker ps |
| All containers | docker ps -a |
| Start Redis | docker start local-redis |
| Stop Redis | docker stop local-redis |
| Restart Redis | docker restart local-redis |
| Redis logs | docker logs local-redis |
| Redis ping | docker exec -it local-redis redis-cli ping |
| Expected response | PONG |
Before starting Spring Boot, verify:
docker exec -it local-redis redis-cli ping returns PONGlocalhost:6379docker ps
|
| Is local-redis running?
|
+-- YES --> docker exec -it local-redis redis-cli ping
| |
| +-- PONG --> Redis is READY
|
+-- NO --> docker ps -a
|
+-- local-redis exists
| |
| +--> docker start local-redis
|
+-- local-redis does not exist
|
+--> docker run -d
--name local-redis
-p 6379:6379
redis:7
docker info
docker ps
docker ps -a
docker start local-redis
docker exec -it local-redis redis-cli ping
docker logs local-redis
Test-NetConnection localhost -Port 6379
docker info
docker ps
docker ps -a
docker start local-redis
docker exec -it local-redis redis-cli ping
docker logs local-redis
sudo systemctl status redis-server
sudo systemctl start redis-server
sudo systemctl restart redis-server
sudo systemctl enable redis-server
redis-cli ping
For Windows local development, Docker Desktop with Redis 7 is generally the simplest approach.
For Linux, Redis can either be run through Docker or installed directly using the Linux package manager.
The most important troubleshooting sequence is:
docker ps
docker ps -a
docker start local-redis
docker logs local-redis
docker exec -it local-redis redis-cli ping
If the final command returns:
PONG
Redis itself is ready. Any remaining
RedisConnectionFailureException in Spring Boot
should then be investigated from the application's Redis
host/port/password configuration or network environment.