Run Redis with Docker
Docker is the fastest path to a local Redis
Section titled “Docker is the fastest path to a local Redis”You do not need to install Redis on your machine. A single docker run command pulls the official image and starts a ready-to-use server in seconds.
The default command explained
Section titled “The default command explained”docker run -d --name redis -p 6379:6379 redis:7-alpine| Flag | What it does |
|---|---|
-d | Run in detached (background) mode so your terminal stays free |
--name redis | Give the container a stable name you can reference in later commands |
-p 6379:6379 | Publish port 6379 from the container to your host on the same port |
redis:7-alpine | Use the official Redis 7 image built on Alpine Linux — small and fast |
Connecting with redis-cli
Section titled “Connecting with redis-cli”Once the container is running, open an interactive CLI session inside it:
docker exec -it redis redis-clidocker exec runs a command inside a running container. -it allocates an interactive TTY so you get the familiar 127.0.0.1:6379> prompt. From there you can run any Redis command.
Adding persistence with a named volume
Section titled “Adding persistence with a named volume”By default the container stores data in a temporary layer that disappears when you remove the container. Attach a named volume to keep your data across restarts:
docker run -d --name redis -p 6379:6379 -v redisdata:/data redis:7-alpineDocker creates the redisdata volume automatically. The /data path is where the official Redis image writes its dump.rdb snapshot file.
Container lifecycle
Section titled “Container lifecycle”# Stop the running container (Redis shuts down cleanly)docker stop redis
# Start it again — data in the named volume is preserveddocker start redis
# Remove the container entirely (volume survives unless you also delete it)docker rm redisViewing logs
Section titled “Viewing logs”# Print all logs produced so fardocker logs redis
# Follow logs in real time (Ctrl-C to stop)docker logs -f redisThe logs show the Redis startup banner, the port it is listening on, and any warnings — useful for diagnosing configuration issues.
docker run -d --name redis -p 6379:6379 redis:7-alpine
docker exec -it redis redis-cli