Disabling Redis persistence in Docker could be a good thing tho, if you are hosting a development environment, running low on disks space and possibly can’t afford to scale. By default, I believe Redis uses the RDB persistence
which basically saves a snapshot in a binary file named dump.rdb
. Now, let’s see how to start a Redis Docker container with no persistence.
Prerequisites
- Docker
Solution
Solution 1. As a part of a Docker Compose stack example:
image: redis:alpine3.15
command: rm -f /data/dump.rdb && redis-server --save "" --appendonly no
As a part of a Docker run
command example:
docker run --name redis_container -d redis:alpine3.15 redis-server --save '' --appendonly no
Solution 2. Since Redis creates an anonymous volume, just before taking down the stack, add the --volumes
flag. For instance:
docker-compose down --volumes
Or use the --renew-anon-volumes
flag when recreating the Docker Compose stack.
docker-compose up --renew-anon-volumes
Note(s): This will affect the rest of the stack services volumes!!!
Solution 3. As a last resort, always make sure to name your persistence volumes, manually find the anonymous Redis Docker volume docker volume ls
, and remove it by using the docker volume rm <volume_name>
command.
Conclusion
If you can think of any other alternative solution, please do let me know in the comment section below. To find more cool Redis commands and hacks, simply browse the Redis category. On a side note, follow our official channel on Telegram.