Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker redis backup

Tags:

docker

I am looking at this example

docker run --rm --volumes-from myredis -v $(pwd)/backup:/backup debian cp /data/dump.rdb /backup/

from Using Docker book.

Why do we need --rm flag?

Why do we have --volumes-from?

like image 587
MikiBelavista Avatar asked May 10 '26 15:05

MikiBelavista


2 Answers

The idea here is that

  • you have a redis container named myredis which has some volumes for persistent storage (that you'd like to backup).
  • you run a temporary debian container that will save the backup to your_current_dir/backup and get removed.

  1. docker run --rm ... debian runs the container and removes it after it exits
  2. --volumes-from myredis this way the debian container will have access to the database
  3. -v $(pwd)/backup:/backup this second volume is used to put the backup at your current dir $(pwd)/backup. If it wasn't used, the backup would have only been copied to /backup (inside the container) and later been removed together with the container. This way the backup persists.
  4. cp /data/dump.rdb /backup/ copies the actual files
like image 121
tgogos Avatar answered May 12 '26 10:05

tgogos


The --rm flag tells Docker Engine to remove the container once it exits. Without this flag, you need to manually remove the container after you stop it.

The --volumes-from flag mounts all the defined volumes from the referenced containers, it ensures the two containers mounts same volumes.

like image 21
Yuankun Avatar answered May 12 '26 12:05

Yuankun