Skip to content

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.

Terminal window
docker run -d --name redis -p 6379:6379 redis:7-alpine
FlagWhat it does
-dRun in detached (background) mode so your terminal stays free
--name redisGive the container a stable name you can reference in later commands
-p 6379:6379Publish port 6379 from the container to your host on the same port
redis:7-alpineUse the official Redis 7 image built on Alpine Linux — small and fast

Once the container is running, open an interactive CLI session inside it:

Terminal window
docker exec -it redis redis-cli

docker 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.

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:

Terminal window
docker run -d --name redis -p 6379:6379 -v redisdata:/data redis:7-alpine

Docker creates the redisdata volume automatically. The /data path is where the official Redis image writes its dump.rdb snapshot file.

Terminal window
# Stop the running container (Redis shuts down cleanly)
docker stop redis
# Start it again — data in the named volume is preserved
docker start redis
# Remove the container entirely (volume survives unless you also delete it)
docker rm redis
Terminal window
# Print all logs produced so far
docker logs redis
# Follow logs in real time (Ctrl-C to stop)
docker logs -f redis

The 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
What does the `-d` flag do in `docker run -d`?
Which flag publishes the Redis port so your host can connect to it?
How do you open an interactive redis-cli session inside the running container?