DEV Community

Cover image for Redis container and persisting

Redis container and persisting

Visakh Vijayan
Willing to learn anything and everything exciting. Always awake. Skips food for fun.
Updated on ・1 min read

Spent quite some time trying to persist data of redis container to the host machine. Here is how to do it finally -

        container_name: redis_db
        command: bash -c "redis-server --appendonly yes --requirepass <password>"
        image: redis
            - "6379:6379"
            - ./redis-volume:/data
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Discussion (1)

softjake profile image
Jacques • Edited

Sure did help, thanks.