vagrant box add命令中使用的URL是什么?

axi*_*sty 9 vagrant

我正在尝试通过完成入门教程来学习Vagrant.但是,只有教程中的几个步骤已经无法正常工作,如教程中所述.具体来说,看起来Vagrant不知道如何下载本教程中使用的框.这是我到目前为止所做的:

看看是否安装了vagrant:

$ which vagrant
Run Code Online (Sandbox Code Playgroud)

安装Vagrant:

$ sudo aptitude install vagrant
The following NEW packages will be installed:
  bsdtar{a} libruby1.9.1{a} libyaml-0-2{a} ruby{a} ruby-childprocess{a} ruby-erubis{a} ruby-ffi{a} ruby-i18n{a} ruby-log4r{a} ruby-net-scp{a} ruby-net-ssh{a} ruby1.9.1{a} vagrant 
0 packages upgraded, 13 newly installed, 0 to remove and 5 not upgraded.
Need to get 0 B/3,451 kB of archives. After unpacking 17.9 MB will be used.
Do you want to continue? [Y/n/?] y
Selecting previously unselected package libyaml-0-2:amd64.
(Reading database ... 171235 files and directories currently installed.)
Preparing to unpack .../libyaml-0-2_0.1.4-3ubuntu3.1_amd64.deb ...
Unpacking libyaml-0-2:amd64 (0.1.4-3ubuntu3.1) ...
Selecting previously unselected package bsdtar.
Preparing to unpack .../bsdtar_3.1.2-7ubuntu2_amd64.deb ...
Unpacking bsdtar (3.1.2-7ubuntu2) ...
Selecting previously unselected package ruby.
Preparing to unpack .../ruby_1%3a1.9.3.4_all.deb ...
Unpacking ruby (1:1.9.3.4) ...
Selecting previously unselected package ruby1.9.1.
Preparing to unpack .../ruby1.9.1_1.9.3.484-2ubuntu1.2_amd64.deb ...
Unpacking ruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Selecting previously unselected package libruby1.9.1.
Preparing to unpack .../libruby1.9.1_1.9.3.484-2ubuntu1.2_amd64.deb ...
Unpacking libruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Selecting previously unselected package ruby-ffi.
Preparing to unpack .../ruby-ffi_1.9.3debian-1ubuntu2_amd64.deb ...
Unpacking ruby-ffi (1.9.3debian-1ubuntu2) ...
Selecting previously unselected package ruby-childprocess.
Preparing to unpack .../ruby-childprocess_0.3.9-2_all.deb ...
Unpacking ruby-childprocess (0.3.9-2) ...
Selecting previously unselected package ruby-erubis.
Preparing to unpack .../ruby-erubis_2.7.0-2_all.deb ...
Unpacking ruby-erubis (2.7.0-2) ...
Selecting previously unselected package ruby-i18n.
Preparing to unpack .../ruby-i18n_0.6.9-1_all.deb ...
Unpacking ruby-i18n (0.6.9-1) ...
Selecting previously unselected package ruby-log4r.
Preparing to unpack .../ruby-log4r_1.1.10-3_all.deb ...
Unpacking ruby-log4r (1.1.10-3) ...
Selecting previously unselected package ruby-net-ssh.
Preparing to unpack .../ruby-net-ssh_1%3a2.6.8-1_all.deb ...
Unpacking ruby-net-ssh (1:2.6.8-1) ...
Selecting previously unselected package ruby-net-scp.
Preparing to unpack .../ruby-net-scp_1.1.1-1_all.deb ...
Unpacking ruby-net-scp (1.1.1-1) ...
Selecting previously unselected package vagrant.
Preparing to unpack .../vagrant_1.4.3-1_all.deb ...
Unpacking vagrant (1.4.3-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for doc-base (0.10.5) ...
Processing 1 added doc-base file...
Registering documents with scrollkeeper...
Setting up libyaml-0-2:amd64 (0.1.4-3ubuntu3.1) ...
Setting up bsdtar (3.1.2-7ubuntu2) ...
Setting up ruby (1:1.9.3.4) ...
Setting up ruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Setting up libruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Setting up ruby-ffi (1.9.3debian-1ubuntu2) ...
Setting up ruby-childprocess (0.3.9-2) ...
Setting up ruby-erubis (2.7.0-2) ...
Setting up ruby-i18n (0.6.9-1) ...
Setting up ruby-log4r (1.1.10-3) ...
Setting up ruby-net-ssh (1:2.6.8-1) ...
Setting up ruby-net-scp (1.1.1-1) ...
Setting up vagrant (1.4.3-1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.5) ...
Run Code Online (Sandbox Code Playgroud)

试试vagrant入门教程:

$ mkdir vagrant_getting_started && cd $_

$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

$ vagrant box add hashicorp/precise32
This command was not invoked properly. The help for this command is
available below.

Usage: vagrant box add <name> <url> [--provider provider] [-h]
    --checksum VALUE             Checksum
    --checksum-type VALUE        Checksum type
-c, --clean                      Remove old temporary download if it exists.
-f, --force                      Overwrite an existing box if it exists.
    --insecure                   If set, SSL certs will not be validated.
    --cacert certfile            CA certificate
    --cert certfile              The client SSL cert
    --provider provider          The provider that backs the box.
-h, --help                       Print this help
Run Code Online (Sandbox Code Playgroud)

根据此输出,我看起来需要指定一个可以从中下载框的URL.因此,根据教程,我搜索了Hashicorp的Atlas盒子目录.我想我找到了正确的资源https://atlas.hashicorp.com/hashicorp/boxes/precise32但是这个资源没有提供可以从中获取框的URL.相反它只是说vagrant up hashicorp/precise32 --provider virtualbox.所以我尝试了这个命令并得到了这个错误:

$ vagrant up hashicorp/precise32 --provider virtualbox
The machine with the name 'hashicorp/precise32' was not found configured for
this Vagrant environment.
Run Code Online (Sandbox Code Playgroud)

在哪里找到应该在vagrant box add <name> <url>命令中使用的URL ?我认为在Hashicorp的盒子目录中很容易找到它,但我没有在任何地方看到它.

以防这是有关我当前环境的有用信息:

$ vagrant box list -i
There are no installed boxes! Use `vagrant box add` to add some.
Run Code Online (Sandbox Code Playgroud)

Bri*_*anC 9

我认为问题是你得到了一个相当旧版本的Vagrant - 1.4.3-1,而最新版本是1.7.2.您安装的存储库可能不再保持最新.

我建议卸载您当前拥有的内容,然后重新安装最新的Vagrant下载.

更新:如果您在Linux上安装Vagrant(Debian或RPM格式包装),您肯定希望从Vagrant下载中下载,因为存储库中的软件包不是最新的并且会很老.

对于Vagrant 1.7.2,框中添加帮助部分说明:

$ vagrant box add -h
Usage: vagrant box add [options] <name, url, or path>

The box descriptor can be the name of a box on HashiCorp's Atlas,
or a URL, or a local .box file, or a local .json file containing
the catalog metadata.
Run Code Online (Sandbox Code Playgroud)

然后,您可以继续按照入门指南进行操作,并可以阅读Boxes文档中的更多内容.

更新2:对于原始问题"我如何找到Box文件的URL?",有两种情况:

  1. 来自HashiCorp的盒子现在托管在他们的Atlas服务上:这些盒子由诸如"hashicorp/precise32"或"ubuntu/trusty64"之类的速记代码识别.我想有一个webservice或约定,其中vagrant命令行可以查询Atlas云,然后找到实际的下载URL.它们似乎没有公开,但你可以通过观察网络流量或查看流浪源来弄明白.

  2. 来自其他项目的框可以是公共的或内部的(公司):这些框通常带有直接指向.box文件的普通URL.您可以在Vagrantbox.es上看到这些示例.事实上,如果你在那里搜索'vagrantup',你会看到很多原始的标准盒子及其URL.

  • 我投了这个答案,并将其标记为正确的答案,但现在我发现虽然这个答案很有用,但它绕过了真正的问题,即有人如何找到用于获取盒子的URL?如果能够专门解决这个问题,你的答案会更好. (2认同)

Mik*_*e D 7

我不清楚为什么你不会只运行,vagrant init hashicorp/precise32因为它处理两个发现并将盒子添加到你的盒子注册表.

但是,如果你真的想看看盒子的来源,即使使用较旧的版本vagrant,你也可以利用这个--debug标志,你会在输出中看到这个盒子的URL 当前的底层 https://atlas.hashicorp.com/hashicorp/boxes/precise32/versions/1.0.0/providers/virtualbox.box.

要回答这个问题(虽然不是这样推荐):

vagrant box add hashicorp/precise32 https://atlas.hashicorp.com/hashicorp/boxes/precise32/versions/1.0.0/providers/virtualbox.box