Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting over images from Hyper-V to WSL2

I recently installed Windows 10 2004 which gives access to WSL2, In doing so, Docker Desktop gives you the option to enabled WSL2 support such that it switches from storing it's containers/volumes in Hyper-V to WSL2. I enabled this feature however it did not port over any of my existing containers or volumes from Hyper-V. Instead it just started fresh.

I was wondering if it is possible to move my existing containers/volumes from Hyper-V to WSL2 such that I don't lose all my volume data and have to rebuild all my containers?

like image 941
ThaDon Avatar asked Jul 13 '20 15:07

ThaDon


1 Answers

To port over existing volumes from Docker on Hyper-V (i.e. pre-WSL2) to Docker based on WSL2:

  1. Make sure you have reverted to Hyper-V; that is, make sure in Docker Desktop Settings -> General you have unchecked the Use the WSL 2 based engine.

Execute the following from an elevated Powershell terminal to backup the volume(s):

docker volume ls (find volume name you want to copy: some_volume)
docker run --rm -v some_volume:/volume -v c:\where-to-backup:/backup alpine tar -cjf /backup/backup.tar.bz2 -C /volume ./
  1. Now, check the Use the WSL 2 based engine setting in Docker Desktop and restore the volume:
docker run --rm -v some_volume:/volume -v c:\where-to-backup:/backup alpine tar -C /volume/ -xjf /backup/backup.tar.bz2
like image 74
ThaDon Avatar answered Oct 04 '22 02:10

ThaDon