Migrating existing containers from Hyper-V to WSL2 technology

不羁的心 提交于 2021-02-16 04:37:08

问题


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:


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



来源:https://stackoverflow.com/questions/62131415/migrating-existing-containers-from-hyper-v-to-wsl2-technology

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!