【问题标题】:What is the URL to be used in the vagrant box add command?在 vagrant box add 命令中使用的 URL 是什么?
【发布时间】:2015-01-17 21:42:15
【问题描述】:

我正在尝试通过入门教程来学习 Vagrant。但是只有进入教程的几个步骤,事情已经不像教程中解释的那样工作了。具体来说,Vagrant 似乎不知道如何下载教程中使用的盒子。这是我到目前为止所做的:

查看是否安装了vagrant:

$ which vagrant

安装 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) ...

试试vagrant getting started tutorial

$ 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

根据此输出,我似乎需要指定一个 URL,从该 URL 可以下载该框。所以,根据教程,我搜索了Hashicorp's Atlas box catalog。我想我找到了位于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.

在哪里可以找到应该在vagrant box add &lt;name&gt; &lt;url&gt; 命令中使用的 URL?我认为在 Hashicorp 的盒子目录中很容易找到它,但我在任何地方都没有看到它。

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

$ vagrant box list -i
There are no installed boxes! Use `vagrant box add` to add some.

【问题讨论】:

    标签: vagrant


    【解决方案1】:

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

    我建议卸载您当前拥有的,然后从 Vagrant downloads 重新安装最新版本。

    更新:如果你在 Linux 上安装 Vagrant,(无论是 Debian 还是 RPM 格式的打包),你肯定想从 Vagrant downloads 下载,因为仓库中的包没有跟上迄今为止,并且会很老。

    对于 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.
    

    然后您可以继续按照入门指南进行操作,并可以在 Boxes documentation 上阅读更多内容。

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

    1. 来自 HashiCorp 的盒子现在托管在其 Atlas service 上:这些盒子由“hashicorp/precise32”或“ubuntu/trusty64”等速记代码标识。我想有一个网络服务或约定,流浪者命令行可以查询阿特拉斯云,然后找到实际的下载 URL。他们似乎没有公开这一点,但您可能可以通过观察网络流量或查看 vagrant 源来弄清楚。

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

    【讨论】:

    • 我在 Lubuntu 14.04.1 上使用 apt-get install vagrant (vagrant -v => 1.4.3) 遇到了同样的问题。从源代码安装时,vagrant 似乎效果最好?!
    • @user77115 是的,我同意 - 我更新了我的答案以明确获得 Vagrant 的最佳方法是通过下载页面(或如您所述从源代码编译)。软件包 repos 似乎不再更新。
    • 我对这个答案投了赞成票,并将其标记为正确答案,但现在我突然想到,虽然这个答案很有用,但它绕过了真正的问题,即有人如何找到使用的 URL去拿盒子?如果能具体解决这个问题,你的答案会更好。
    • @axiopisty 好点 - 回答原始问题 :) 我刚刚添加了第二次更新以进一步扩展;希望对您有所帮助。
    【解决方案2】:

    我不清楚你为什么不直接运行 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

    【讨论】:

    • 为了澄清为什么流浪的新手不会运行vagrant init hashicorp/precise32,原因是因为在 OP 中链接的教程并没有说要那样做。它特别说:vagrant init,然后是vagrant box add hashicorp/precise32。使用发行版存储库中可用的 vagrant 版本,这会导致 OP 中指定的错误。当然,对于不知道 url 的人以及知道它甚至是一种选择的人来说,使用这种方法是另一种选择。遵循本教程的人可能没有这些信息。
    【解决方案3】:

    与:

    ~ » vagrant version
    Installed Version: 2.0.1
    Latest Version: 2.0.1
    
    You're running an up-to-date version of Vagrant!
    

    您可以简单地发出一个 curl 请求来取回数据。见下文:

    ~ » curl -i -L https://vagrantcloud.com/sakhan/ubuntu1404-contrail-devstack1
    HTTP/1.1 301 Moved Permanently
    Server: Cowboy
    Date: Fri, 19 Jan 2018 18:08:40 GMT
    Connection: keep-alive
    Location: https://vagrantcloud.com/sakhan/boxes/ubuntu1404-contrail-devstack1
    Content-Type: text/html
    Cache-Control: no-cache
    X-Request-Id: cfcc4360-34f5-41d2-91ce-1eb82e5a6b7c
    X-Runtime: 0.004783
    Content-Length: 133
    Via: 1.1 vegur
    
    HTTP/1.1 302 Found
    Server: Cowboy
    Date: Fri, 19 Jan 2018 18:08:40 GMT
    Connection: keep-alive
    X-Frame-Options: SAMEORIGIN
    X-Xss-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
    Location: https://app.vagrantup.com/sakhan/boxes/ubuntu1404-contrail-devstack1
    Content-Type: text/html; charset=utf-8
    Cache-Control: no-cache
    X-Request-Id: 1383ab1f-8ed8-4e81-9762-d5ffacdda9f3
    X-Runtime: 0.008575
    Transfer-Encoding: chunked
    Via: 1.1 vegur
    
    HTTP/1.1 200 OK
    Server: Cowboy
    Date: Fri, 19 Jan 2018 18:08:41 GMT
    Connection: keep-alive
    X-Frame-Options: SAMEORIGIN
    X-Xss-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
    Content-Type: application/json; charset=utf-8
    Etag: W/"af57ca8e837f7cdd4c3047e2752a506f"
    Cache-Control: max-age=0, private, must-revalidate
    X-Request-Id: b0296c54-8ffc-408b-89e5-e361df1bb6c8
    X-Runtime: 0.051198
    Transfer-Encoding: chunked
    Via: 1.1 vegur
    
    {"description":"Vagrant box having Opencontail + Devstack environment","short_description":"Vagrant box having Opencontail + Devstack environment","name":"sakhan/ubuntu1404-contrail-devstack1","versions":[{"version":"0.0.2","status":"active","description_html":"<p>Vagrant box with opencontrail_devstack version 0.0.2</p>\n","description_markdown":"Vagrant box with opencontrail_devstack version 0.0.2","providers":[{"name":"virtualbox","url":"https://vagrantcloud.com/sakhan/boxes/ubuntu1404-contrail-devstack1/versions/0.0.2/providers/virtualbox.box"}]}]}
    

    所以最后,你有以下 json 信息:

    providers:
        name: virtualbox
        url: https://vagrantcloud.com/sakh...ons/0.0.2/providers/virtualbox.box
    

    HTH

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 2013-06-02
      • 2019-06-21
      • 1970-01-01
      • 2016-11-02
      • 1970-01-01
      • 2012-07-10
      相关资源
      最近更新 更多