laravel 如何复制流浪盒再次使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26435510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:17:46  来源:igfitidea点击:

How to copy vagrant box to reuse again

ubuntularavelvagrant

提问by Abhinav Gauniyal

I have downloaded Homestead box thrid time this month by using vagrant box add laravel/homestead. I currently do not have access to fast internet so its pretty much annoying to download it everytime. Is there a way to use the downloaded package again and include the local package in vagrant , it dosent matters if projects or synced locations are preserved or not.

我本月第三次使用vagrant box add laravel/homestead下载了 Homestead box 。我目前无法访问快速互联网,因此每次下载它都非常烦人。有没有办法再次使用下载的包并将本地包包含在 vagrant 中,是否保留项目或同步位置无关紧要。

I am on Ubuntu machine if that matters.

如果这很重要,我在 Ubuntu 机器上。

Update : I need the downloaded Homestead box so that if my machine goes down or I have to install it somewhere else with no/slow internet connectivity , I can do it locally.

更新:我需要下载的 Homestead 盒子,这样如果我的机器出现故障或者我必须将它安装在没有/慢速互联网连接的其他地方,我可以在本地完成。

回答by benbot

Oh that's pretty easy.

哦,这很容易。

To pack up your currently installed box back into a .box file (while keeping it installed on your system) just use vagrant box listto find the box name, provider, and version.

要将当前安装的 box 打包回 .box 文件(同时将其安装在您的系统上),只需使用vagrant box list查找 box 名称、提供者和版本即可。

Then use vagrant box repackage <name> <provider> <version>and it will pack it up into a file called package.box.

然后使用vagrant box repackage <name> <provider> <version>,它会打包成一个名为 package.box 的文件。

Hope This Helped !

希望这有帮助!

回答by Sankalp Singha

A better way to do it is :

一个更好的方法是:

  1. Just go to the directory where you have done the Vagrant init
  2. Do a vagrant package --output mynew.box
  1. 只需转到您完成的目录 Vagrant init
  2. 做一个 vagrant package --output mynew.box

You will get the box packaged into the mynew.box file which you can even copy and share with your other developers. This is pretty useful in my opinion where you have slower internet speed.

您将把盒子打包到 mynew.box 文件中,您甚至可以复制该文件并与其他开发人员共享。在我看来,当您的网速较慢时,这非常有用。

回答by Rodrigo Queiroz

Just to complement @thecodethinkeranswer.

只是为了补充@thecodethinker 的答案。

When I applied the suggested command:

当我应用建议的命令时:

vagrant box list

vagrant box list

and

vagrant box repackage <name> <provider> <version>

vagrant box repackage <name> <provider> <version>

The following happened:

发生了以下情况:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'laravel/homestead' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0.4.0
==> default: Loading metadata for box 'laravel/homestead'
default: URL: https://atlas.hashicorp.com/laravel/homestead
==> default: Adding box 'laravel/homestead' (v0.5.0) for provider: virtualbox
default: Downloading: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.5.0/providers/virtualbox.box

As you can see, it did not recognise the package.boxand is trying to download from the internet. If you look closely above you can see that is looking for box version >= 0.4.0.

如您所见,它无法识别package.box并尝试从 Internet 下载。如果你仔细看上面,你可以看到正在寻找box version >= 0.4.0.

This is the result of vagrant box list:

这是结果vagrant box list

laravel/homestead (virtualbox, 0)

laravel/homestead (virtualbox, 0)

Because the box was added manually. The box metadata was not available and by default it will set the version to 0.

因为盒子是手动添加的。框元数据不可用,默认情况下它将版本设置为 0。

To fix the problem, create a metadata.json:

要解决此问题,请创建一个metadata.json

{
"name": "laravel/homestead",
    "versions": [{
        "version": "0.4.0",
        "providers": [{
            "name": "virtualbox",
            "url": "file://package.box"
        }]
    }]
}

Because now we have a proper metadata, you can do:

因为现在我们有了合适的元数据,您可以执行以下操作:

vagrant box add metadata.json

vagrant box add metadata.json