将现有容器从Hyper-V迁移到WSL2技术 [英] Migrating existing containers from Hyper-V to WSL2 technology
问题描述
在DockerCon 2020之后,我热情地下载了Windows 10 2004,并尝试将Docker Desktop升级到WSL 2容器并进行了实验.
After DockerCon 2020, I enthusiastically downloaded Windows 10 2004 and tried to upgrade Docker Desktop to WSL 2 containers and experiment.
我有几个容器,特别是几个连同其数据存储在卷中的数据库.Postgres和MS SQL Server.
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.
我不想丢失数据,尽管它并不重要.我之所以使用Docker卷而不是OS挂载,是因为我一再发现,不不建议使用Windows挂载进行数据库数据存储.
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.
当我第一次启用WSL-2时,我所有的容器和卷都消失了.
When I enabled WSL-2 for the first time, all my containers and volumes disappeared.
我想问一下是否有(推荐的)过程或工具将基于Hyper-V的容器及其数据迁移到WSL-2.
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.
可以轻松地重新下载图像.容器设置和数据迁移到WSL-2怎么样?
Images can be easily redownloaded. How about container setup and data migration to WSL-2?
我当然可以可以手动进行.我可以使用 busybox
将卷转储到本地驱动器(作为tar),并使用另一个busybox实例进行还原
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
推荐答案
当然,这是我的经验分享.
Of course, here is my sharing of experience.
首先,您需要记住或重构语法以启动容器,以便稍后重新运行它们.想法是从现有容器中收集尽可能多的信息以重新运行它们
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
这是一个很好的起点
##迁移卷
介于易执行性和长时间运行的任务之间.容易,因为只用了一个容器,又麻烦又麻烦,因为它需要多个命令
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
就我而言,Oracle 12c/19c已构建但从未推出.构建Oracle是一件痛苦的事情,因为您必须在下载其许可的ZIP文件后再构建容器
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
明智地使用 docker save -o
.例子
docker save oracledb:12.0.0.0c -o oracledb.img
##还原图像
切换到WSL-2后,明智地使用 docker load
After switching to WSL-2, use docker load
wisely
使用 docker volume create
手动重新创建所有卷,并使用busybox解压缩.这有点相反
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
还原容器
现在您有了源Docker命令行-s,启动它们以重新创建容器.
Restore containers
Now that you have your source Docker commandline-s, launch them to recreate containers.
结论:我正在考虑制作可重用的Powershell脚本
Conclusion: I am thinking about making a reusable Powershell script
这篇关于将现有容器从Hyper-V迁移到WSL2技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!