Skip to content
Runbook

Install Redis on Docker

Ultra-fast in-memory key-value database, used as a cache, message broker, and session store.

Cachecachein-memorykey-valuenosqlpub-subbroker

Installation

Container (official image) · Docker
docker run -d --name redis -p 6379:6379 -v redisdata:/data redis:7

Named volume redisdata to persist data across restarts.

Verify the installation

Verify
docker exec redis redis-cli ping

Important files

TypePathDescription
data/dataPersistence directory in the container (dump.rdb / appendonly.aof), mounted here on the redisdata volume.

Default ports

6379

Command-line tools

  • redis-cliAvailable in the container: `docker exec -it redis redis-cli`.

Uninstall

Remove the container
docker rm -f redis
Also remove the data volume
docker volume rm redisdata

Good to know

  • The official redis image does not enable AOF by default. For more durable persistence, add `--appendonly yes` at the end of the command, after the image name.

Running with Docker

The official redis image from Docker Hub is the simplest and most reproducible way to run Redis, including on macOS and Windows. The command publishes port 6379 on the host and mounts a named volume redisdata on /data, the directory where Redis writes its persistence files. Pin a version (redis:7) rather than latest for deterministic deployments.

Persistence and configuration

By default, the image writes an RDB snapshot to /data. To enable the append-only log (more durable), add the option at the end: docker run -d --name redis -p 6379:6379 -v redisdata:/data redis:7 redis-server --appendonly yes. For a full configuration, mount your own redis.conf (-v ./redis.conf:/usr/local/etc/redis/redis.conf) and run redis-server /usr/local/etc/redis/redis.conf.

Interaction and security

Connect to the server with docker exec -it redis redis-cli. To add a password without a configuration file, pass --requirepass <password> after the image name. Only publish port 6379 on 0.0.0.0 if access is protected (password + firewall); in development, prefer binding the port to the loopback, for example -p 127.0.0.1:6379:6379.