Search code examples
dockertardocker-volumemounted-volumes

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:

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