如何导出一个 Vagrant 虚拟机来传输它 [英] How to export a Vagrant virtual machine to transfer it

查看:24
本文介绍了如何导出一个 Vagrant 虚拟机来传输它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 vagrant box 启动并运行(配置了一个 LAMP 堆栈).我需要把它转移到另一台电脑上.我怎样才能导出它?我想我可以获得一个可以复制到另一台 PC 的文件(或多个文件),这样我就可以运行一些命令来导入 vagrant 框.

解决方案

你有两种方法可以做到这一点,我称之为 dirty wayclean way:

1.肮脏的方式

使用 vagrant package 命令从您当前的虚拟环境创建一个盒子:

http://docs.vagrantup.com/v2/cli/package.html

然后将盒子复制到另一台电脑上,使用 vagrant box add 添加它,然后像往常一样使用 vagrant up 运行它.

请记住,当虚拟机启动时,您的工作目录中的文件(带有 Vagrantfile 的文件)是共享的,因此您也需要将其复制到另一台电脑上.

2.干净方式

理论上永远不需要使用 Vagrant 进行导出/导入.如果您有先见之明,可以使用 Provisioning 来配置虚拟环境(chef、puppet、ansible),并使用 git 等版本控制系统作为您的工作目录,那么此时复制环境就像运行一样简单:

git clone 流浪起来

I have a vagrant box up and running (configured with a LAMP stack). I need to transfer it to another PC. How can I export it? I guess that I can get a file (or files) that can be copied to another PC, so there I can run some command to import the vagrant box.

解决方案

You have two ways to do this, I'll call it dirty way and clean way:

1. The dirty way

Create a box from your current virtual environment, using vagrant package command:

http://docs.vagrantup.com/v2/cli/package.html

Then copy the box to the other pc, add it using vagrant box add and run it using vagrant up as usual.

Keep in mind that files in your working directory (the one with the Vagrantfile) are shared when the virtual machine boots, so you need to copy it to the other pc as well.

2. The clean way

Theoretically it should never be necessary to do export/import with Vagrant. If you have the foresight to use provisioning for configuring the virtual environment (chef, puppet, ansible), and a version control system like git for your working directory, copying an environment would be at this point simple as running:

git clone <your_repo>
vagrant up

这篇关于如何导出一个 Vagrant 虚拟机来传输它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆