17

After DockerCon 2020, I enthusiastically downloaded Windows 10 2004 and tried to upgrade Docker Desktop to WSL 2 containers and experiment.

I had a few containers, in particular a couple of databases along with their data stored within volumes. Postgres and MS SQL Server in the case.

I wouldn't like to lose the data, though it's not critical. I used Docker volumes rather than OS mounts because I have repeatedly seen that using Windows mounts for database data storage is not recommended.

When I enabled WSL-2 for the first time, all my containers and volumes disappeared.

I'd like to ask if there is any (recommended) procedure or tool to mgirate Hyper-V based containers to WSL-2 along with their data.

Images can be easily redownloaded. How about container setup and data migration to WSL-2?

Of course I can do it manually. I can dump the volumes to my local drive (as a tar) using busybox and restore using another busybox instance

1 Answer 1

11

Of course, here is my sharing of experience.

Reconstruct the docker run syntax

First, you need to remember or reconstruct the syntax to start the container to re-run them later. The idea is to collect as much information as possible from existing containers to re-run them

Here is a good starting point

Migrating volumes

That's between ease of execution and long-running task. Easy because it took me simply one container, long and tedious because it requires multiple commands

docker run `
           --rm ` #Dispose after use
           -v G:\Docker:/volumes ` # Mount my Windows drive so that the file will appear in Explorer
           - v src_mount:/src ` # e.g. mssql2017:/mssql2017 mounts mssql2017 named volume to Busybox
           busybox `
           tar -zcvf /volumes/backup_name.tar.gz /src

Rinse and repeat for all named volumes of your interest. I had a bunch only

Dump images you won't be able/willing to reconstruct

In my case, Oracle 12c/19c were built but never pushed. Building Oracle is painful becuase you have to build the container after downloading their licensed ZIP file

Use docker save -o wisely. Example

docker save oracledb:12.0.0.0c -o oracledb.img

Restore images

After switching to WSL-2, use docker load wisely

Restore volumes

Manually recreate all volumes with docker volume create and unzip with busybox. This is kind of a reverse

docker run `
       --rm ` #Dispose after use
       -v G:\Docker:/volumes ` # Mount my Windows drive so that the file will appear in Explorer
       - v dest_mount:/dest ` # e.g. mssql2017:/mssql2017 mounts mssql2017 named volume to Busybox
       busybox `
       tar -zxvf /volumes/backup_name.tar.gz /dest

Restore containers

Now that you have your source Docker commandline-s, launch them to recreate containers.

Conclusion: I am thinking about making a reusable Powershell script

3
  • Did you ever create that script? 😜 I just switched to wsl2 tonight and have a TON of named volumes on my hyper v vm. 🥴 Commented Aug 26, 2020 at 10:41
  • Of course never. I know that I promise myself to do a lot of things... but I have a TON of work to care about Commented Aug 26, 2020 at 11:50
  • 1
    One hint about reconstructing the docker run syntax: stackoverflow.com/questions/32758793/… links to a tool which programmatically derives the docker run command from a container. Commented Oct 1, 2020 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.