Spent quite some time trying to persist data of redis container to the host machine. Here is how to do it finally -
redis_db: container_name: redis_db command: bash -c "redis-server --appendonly yes --requirepass <password>" image: redis ports: - "6379:6379" volumes: - ./redis-volume:/data
Here I have mapped the host's redis-volume folder with the /data folder of the redis container. Once done you will be able to find files called appendonly.aof and dump.rdb inside it. You will be able to see these files inside your container at /data as well. To see that use
> docker ps > docker exec -it <containerId> bash # cd /data
When you start your container up, you will find a line like so -
redis_db | 1:M 08 Jun 2020 19:58:58.987 * DB loaded from append only file: 0.000 seconds
Also, change the persmissions of the host folder to a writable one.
Hope this helps someone! :D