Dragonfly Cloud is now available on the AWS Marketplace - Learn More

Question: Where Does Redis Store Data in Docker?

Answer

Redis, when running inside a Docker container, stores its data in the same default location as it would outside the container. The default location of the Redis data storage is /data within the container.

To persist Redis data across container restarts or removal, you should mount a volume from the host machine to the /data directory inside the container. Here's an example using docker run command:

docker run -d --name redis-container \ -v /path/to/your/host/directory:/data \ redis:latest

In this example, replace /path/to/your/host/directory with the actual path to the desired directory on your host machine. This will ensure that the Redis data inside the container persists even after the container is stopped or removed.

Additionally, if you're using docker-compose, here is an example of how to define a Redis service with a named volume:

version: '3' services: redis: image: "redis:latest" volumes: - redis-data:/data volumes: redis-data: driver: local

By using this docker-compose.yml file and running docker-compose up, Redis data will be stored in a named volume called redis-data.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost