Can I recover docker volumes from a file system bavkup?

I have a systemwide backup of my PC and I have lost the Docker volumes. Is it possible to recover the Docker volumes from a file level backup? How should I go about it?

In other words, how can I somehow import file level backups of docker volumes to a new docker installation?

You can check the /var/lib/docker/volumes folder if you’re able to see your data in there and extract it out

I see a lot of confusion recently around Docker and Docker Desktop. They are not the same. You mention Docker, but I guess you have chosen the right category and you are running Docker Desktop for Windows, so your volumes are inside the virtual machine so you would have to search for the volumes in the WSL distribution if you use the WSL2 backend.

In my case (Latest Windows 11, Docker Desktop 4.13) it is in the “docker-desktop-data” WSL2 distribution at the following location:

/data/docker/volumes

You can access it from the file explorer even when Docker Desktop is not running by using the following path:

\\wsl.localhost\docker-desktop-data\data\docker\volumes

Since we are not talking about creating backups but restoring them, the question is how did you create that backup. If you have a backup for the WSL2 distro, you could restore the whole distro I guess, but I am not 100 percent sure that it would work flawlessly. If you backed up the data on the actual volumes directly, you could just recreate a volume using docker volume create and extract the backup (if it is an archive), mount the volume to a container and copy the data to the container:

docker cp ./data containername:/volume/mount/point

You can also use the “Volume Backup & Share” Docker extension and just click on “Import into new Volume”

This is exactly how I currently make backups of my entire Docker DEV environment using wsl export and compressing the file afterwards.
The goal is to quickly back up all built images and volumes, so one can restore the DEV environment if something blows up.

But I haven’t got the chance to actually try to restore the Docker from the backup yet (with wsl import).

Why are you not 100% sure that importing the WSL2 distro (docker-desktop-data) would work flawlessly?

Does the docker-desktop-data distro contain some installation-specific logic that would conflict when imported in another machine (or in the same machine after eg clean Windows install)?

Maybe docker-desktop-data distro contains some Docker Desktop version-specific logic that would conflict when imported into a machine where the version of the Docker Desktop differs?

Because I haven’t seen this suggested in the documentation. I guess it would work almost always, unless there is something on Windows that should be restored at the same time. I don’t know the files of Docker Desktop well enough to be 100% sure.

I can’t say that for sure, but it is possible. If not today, then maybe in the future.

To sumarize I had two reasons not to be sure:

  1. Exactly what you guessed: possible incompatibility between Docker Desktop versions
  2. Restoring only the data in the WSL distro might not be enough sometimes

As I mentioned in my post, I have a whole system backup of the windows pc with Synology Active Backup for Business…

I was wondering if I could just recover some specific files in order to be able to recover the data.
Any one know how could I restore the docker-desktop-data distro from a file level backup? (not a pure docker related question)

To be precise, you didn’t mention Synology Active Backup :slight_smile: Depending on how a backup is created the solution could be different. Since unfortunately I don’t know Synology, I still can’t give you a better answer based on that.

You could try the method what @elenderik used if you can get the files of the distro out of the whole backup and import the WSL distro. Make sure you install the same Docker Desktop version that you had when you created the backup.

If it doesn’t work, then try to find the volumes in the backup and use the backup extension of Docker Desktop to restore the files.

I stand corrected, I did not mention Synology Active Backup, but it basically allows me to recover whatever files where present in the pc when I did the backup. The problem with aplying @elenderik method for recovery is that I did not do an WSL export, and therefore, can’t do an import. I would need to know how to recover the WSL by recovering whatever files it is stored in.
I am atempting to recover the whole system into a Virtualbox virtual machine and then export the data from there, but I am facing some issues booting the Virtual machine. That is why knowing which files to recover would be helpfull.

I see. I am not sure if it is enough, but I checked my Windows 11 and I found these:

  • C:\Users\<username>\AppData\local\Docker\wsl: I guess the “data” folder contains the vhdx of docker-desktop-data and “distro” is docker-desktop.
  • C:\ProgramData\Docker: The files of the Windows containers
  • C:\ProgramData\DockerDesktop\vm-data: I am not sure what is the difference between this and the “wsl” folder.

You could try to mount the vhdx files to somewhere to figure it out before restoring. If restoring doesn’t work, but you can mount the vhdx files, you can try to find the docker data root and the volumes folder in it.

update:

You probably need to register the vhdx files as the storages of the WSL distros, but I don’t know how that should be done…

I WAS ABLE TO RECOVER THE INFORMATION

Thank you very much @rimelek, the information you provided was invaluable in order to be able to recover the data.
This is what I did, it might be valuable for someone else. Even though it worked in my situation, it might not work to someone else, but it is certainly worth a try.

  1. Located the .vhdx file in C:\Users\<username>\AppData\local\Docker\wsl\data\ in the backup and recovered it. In my case this was a 6GB file.
  2. Stop all services related to docked and hipervisor (otherwise I was unable to overwrite the current .vhdx file with the one recovered from the backup. I had a newly installed docker-desktop wich was almost the same version as the one I previously had.
  3. Replace the C:\Users\<username>\AppData\local\Docker\wsl\data\ext4.vhdx file of the current docker-desktop instance with the one I recovered from the backup.
  4. Rebooted the PC and it all worked again with all my data and my container as if nothing had happened.

Once again … Thank you for your assistance.

1 Like