Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to back up a volume from Docker via PowerShell – .tar file is nowhere to be seen

I’ve got a basic wordpress setup to test/learn Docker and i’m in the process of teating/learning to migrate it to a live server by backing up the containers, and volumes.

I can back up the ‘containers’ no problem using the save/load commands, but cant seem to get the volumes backed up.

I’ve run the command on my containers as advised in the docker documentation here: https://docs.docker.com/storage/volumes/. The command is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

docker run --rm --volumes-from wordpress_db_1 -v c:\:/backup ubuntu tar cvf backup.tar /var/lib/mysql

I’ve also tried

docker run --rm --volumes-from wordpress_db_1 -v /mnt/c/users/me/desktop:/backup ubuntu tar cvf backup.tar /var/lib/mysql

Both commands run without fault, however i cant find the .tar output anywhere – where is it being saved? or am i doing something wrong?

>Solution :

Your tar file is created in the work directory in the container. When the container stops, the container is removed and the file is lost. You need to specify that the file should be created in the /backup directory like this

docker run --rm --volumes-from wordpress_db_1 -v c:\:/backup ubuntu tar cvf /backup/backup.tar /var/lib/mysql

One thing to note is that by mapping the root of your C drive, you give the container full access to the whole disk. So be careful 🙂 It would be safer to map the %temp% or another directory like this

docker run --rm --volumes-from wordpress_db_1 -v %temp%:/backup ubuntu tar cvf /backup/backup.tar /var/lib/mysql
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading