如何将Vagrant Box转换为Docker镜像 [英] How to convert a Vagrant box to a Docker image
问题描述
有没有办法将Vagrant框转换为Docker图像?
我在我的Github项目中使用EC2框和Virtualbox框重播了这个项目 blacklabelops / centos的。我已经准备了一个Vagrantfile,必要的安装,你可以尝试一下你的Vagrant箱子。
EC2框:
-
使用 https://github.com/katzj/创建和设置AMI映像ami-creator - 我的存储库中的脚本。
-
之后使用Guestfish将图像解压缩到压缩文件。 - 我的存储库中的脚本。
-
在Docker中导入tarball。 - 我的存储库中的示例。
现在,使用Vagrant Virtualbox,可以使用提供的Vagrantfile重播命令。只需复制存储库,将其旋转并键入:
$ qemu-img convert -f vmdk -O raw MyTry-disk1。 vmdk mytry.img
Vagrant框的VMDK可以在Virtualbox中找到文件夹,通常〜/ VirtualBox\ VMs /.
创建后,您可以应用Guestfish。
$ guestfish -a mytry.img --ro
$>< fs>运行
注意:tty
< blockquote>
$>< fs> list-filesystems
/ dev / sda1:ext4
/ dev / VolGroup / lv_root:ext4
/ dev / VolGroup / lv_swap:swap
$>< fs& mount / dev / VolGroup / lv_root /
$>< fs> tar-out / - | xz-best>>> mytry.xz
$>< fs>退出
注意:退出tty
导入docker:
$ cat mytry.xz | docker import - mytryimage
查看容器内部
$ docker run -it mytryimage bash
I saw that it's possible to convert a Docker image into a Vagrant box.
Is there a way to convert a Vagrant box into a Docker image?
解决方案I replayed this with EC2 boxes and Virtualbox boxes in my Github project blacklabelops/centos. I have prepared a Vagrantfile with the necessary installation and you can try it yourself with your Vagrant boxes.
EC2 boxes:
Create and provision an AMI image with https://github.com/katzj/ami-creator - Skripts in my repository.
Afterwards use Guestfish in order to extract the image into a tarball. - Skripts in my repository.
Import the tarball inside Docker. - Example in my repository.
And now with Vagrant Virtualbox, commands can be replayed with my provided Vagrantfile. Just clone the repository, spin it up and type:
$ qemu-img convert -f vmdk -O raw MyTry-disk1.vmdk mytry.img
The Vagrant box's VMDK can be found in the Virtualbox folder, usually ~/VirtualBox\ VMs/.
After the raw has been created you can apply Guestfish.
$ guestfish -a mytry.img --ro $ ><fs> run
Note: tty
$ ><fs> list-filesystems /dev/sda1: ext4 /dev/VolGroup/lv_root: ext4 /dev/VolGroup/lv_swap: swap $ ><fs> mount /dev/VolGroup/lv_root / $ ><fs> tar-out / - | xz --best >> mytry.xz $ ><fs> exit
Note: exiting tty
Importing into docker:
$ cat mytry.xz | docker import - mytryimage
Look inside the container
$ docker run -it mytryimage bash
这篇关于如何将Vagrant Box转换为Docker镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!