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
Depending on your system's hardware performance, you likely found that WSL2 is the faster option. To expedite the process of running Ubuntu Linux on Hyper-V, you could set up SSH access to the virtual machine. This speeds up command-line access.
WSL 2 uses the latest and greatest in virtualization technology to run a Linux kernel inside of a lightweight utility virtual machine (VM). However, WSL 2 is not a traditional VM experience. This guide will compare WSL 1 and WSL 2, including exceptions for using WSL 1 rather than WSL 2.
Docker Desktop on Windows 10 supports two backends: HyperV and WSL2. WSL2 in turn also uses Hyper-V — so without having Hyper-V enabled Docker Desktop fails to start and can't be used.
With the WSL 2 backend supported in Docker Desktop for Windows, you can work in a Linux-based development environment and build Linux-based containers, while using Visual Studio Code for code editing and debugging, and running your container in the Microsoft Edge browser on Windows.
Of course, here is my sharing of experience.
run
syntaxFirst, 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
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
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
After switching to WSL-2, use docker load
wisely
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
Now that you have your source Docker commandline-s, launch them to recreate containers.
Conclusion: I am thinking about making a reusable Powershell script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With