How to convert a Vagrant box to a Docker image

你。 提交于 2019-12-03 04:22:47

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/31321076/how-to-convert-a-vagrant-box-to-a-docker-image

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