windows 如何将下载的 .box 文件添加到 Vagrant?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22065698/
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-09 11:24:46  来源:igfitidea点击:

How to add a downloaded .box file to Vagrant?

windowsvagrant

提问by Petrus Theron

How do I add a downloaded .boxfile to Vagrant's list of available boxes? The .boxfile is located on an external drive.

如何将下载的.box文件添加到 Vagrant 的可用框列表中?该.box文件位于外部驱动器上。

I tried running vagrant box add my-box d:/path/to/box, but Vagrant interprets the path as a URL.

我尝试运行vagrant box add my-box d:/path/to/box,但 Vagrant 将路径解释为 URL。

回答by Petrus Theron

Solution:

解决方案:

vagrant box add my-box file:///d:/path/to/file.box

Has to be in a URL format.

必须是 URL 格式。

回答by Sameera Thilakasiri

You can point to the folder where vagrant and copy the box file to same location. Then after you may run as follows

您可以指向 vagrant 所在的文件夹并将 box 文件复制到同一位置。然后你可以按如下方式运行

vagrant box add my-box name-of-the-box.box
vagrant init my-box
vagrant up

Just to check status

只是为了检查状态

vagrant status

回答by Terry Wang

Try to change directory to where the .boxis saved

尝试将目录更改.box为保存的位置

Run vagrant box add my-box downloaded.box, this may work as it avoids absolute path (on Windows?).

Run vagrant box add my-box downloaded.box,这可能会起作用,因为它避免了绝对路径(在 Windows 上?)。

回答by langlauf.io

Solution for Windows:

Windows 解决方案:

  • Open the cmd or powershell as admin
  • CD into the folder containing the .boxfile
  • vagrant box add --name name_of_my_box 'name_of_my_box.box'
  • vagrant box listshould show the new box in the list
  • 以管理员身份打开 cmd 或 powershell
  • CD 到包含.box文件的文件夹中
  • vagrant box add --name name_of_my_box 'name_of_my_box.box'
  • vagrant box list应该在列表中显示新框

Solution for MAC:

MAC的解决方案:

  • Open terminal
  • CD into the folder containing the .boxfile
  • vagrant box add --name name_of_my_box "./name_of_my_box.box"
  • vagrant box listshould show the new box in the list
  • 打开终端
  • CD 到包含.box文件的文件夹中
  • vagrant box add --name name_of_my_box "./name_of_my_box.box"
  • vagrant box list应该在列表中显示新框

回答by Ashfaq

First rename the Vagrantfile then

首先重命名 Vagrantfile 然后

vagrant box add new-box name-of-the-box.box
vagrant init new-box
vagrant up

Just to check status

只是为了检查状态

vagrant status

that's all

就这样

回答by Jakhongir

Alternatively to add downloaded box, a json file with metadata can be created. This way some additional details can be applied. For example to import box and specifying its version create file:

或者添加下载的框,可以创建一个带有元数据的 json 文件。这样可以应用一些额外的细节。例如导入框并指定其版本创建文件:

{
  "name": "laravel/homestead",
  "versions": [
    {
      "version": "7.0.0",
      "providers": [
        {
          "name": "virtualbox",
          "url": "file:///path/to/box/virtualbox.box"
        }
      ]
    }
  ]
}

Then run vagrant box addcommand with parameter:

然后运行vagrant box add带参数的命令:

vagrant box add laravel/homestead /path/to/metadata.json

回答by bhapat

F:\PuppetLab\src\boxes>vagrant box add precise32 file:///F:/PuppetLab/src/boxes/precise32.box
==> box: Adding box 'precise32' (v0) for provider:
    box: Downloading: file:///F:/PuppetLab/src/boxes/precise32.box
    box: Progress: 100% (Rate: 1200k/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'precise32' (v0) for 'virtualbox'!

回答by Dmitriy Vinokurov

Just to add description for another one case. I've got to install similar Vagrant Ubuntu 18.04 based configurations to multiple Ubuntu machines. Downloaded bionic64 box to one using vagrant upwith Vagrantfilewhere this box was specified, then copied folder .vagrant.d/boxes/ubuntu-VAGRANTSLASH-bionic64to others.

只是为了添加另一个案例的描述。我必须在多台 Ubuntu 机器上安装类似的基于 Vagrant Ubuntu 18.04 的配置。使用下载bionic64箱一个vagrant upVagrantfile其中指定此框,然后复制文件夹.vagrant.d/boxes/ubuntu-VAGRANTSLASH-bionic64给他人。