Redis › Redis with Docker & Kubernetes

How do you persist Redis data when running it in a Docker container, so data survives a container restart?

Beginner

Answer

You mount a Docker volume to the directory where Redis stores its persistence files, ensuring that even if the container is stopped, removed, and recreated, the underlying data files remain safely stored on the host machine or in a Docker managed volume, ready to be loaded again by a new container instance.
docker run --name my-redis -p 6379:6379 -v redis-data:/data -d redis:latest --save 60 1
Real-world example A team running Redis in Docker for a staging environment mounts a persistent volume, ensuring their test data survives even when they periodically recreate the container during deployments.

Common follow-ups: What is the difference between a named volume and a bind mount for this purpose?;Does the container need any special configuration to actually save data to the mounted directory?