执行以下命令后,.box文件会发生什么?
vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
下载完成后,我在文件系统中找不到 lucid32.box
文件。
执行以下命令后,.box文件会发生什么?
vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
下载完成后,我在文件系统中找不到 lucid32.box
文件。
正如文档中所提到的,虚拟机镜像存储在以下位置:
~/.vagrant.d/boxes
C:/Users/USERNAME/.vagrant.d/boxes
C:\Users\{用户名}\.vagrant.d\boxes
目录下,我只发现了.vmdk
文件,没有发现.box
文件!! - Bilal在 Mac/Linux 系统上,已成功下载的文件位于:
~/.vagrant.d/boxes
失败的方框位于:
~/.vagrant.d/tmp
在Windows系统中,它位于“用户”文件夹下:
C:\Users\%userprofile%\.vagrant.d\boxes
希望这能有所帮助。谢谢。
~/.vagrant.d/boxes
不会存储 .box 文件本身,仅存储其内容。~/.vagrant/tmp
用于在下载时暂时存储 .box 文件,但在 Vagrant 安装后会被删除。 - Luke Peterson%userprofile%\.vagrant.d\boxes
。 - J. Scott Elblein要更改路径,您可以将新的路径设置为名为VAGRANT_HOME的环境变量。
export VAGRANT_HOME=my/new/path/goes/here/
如果您希望将这些虚拟机映像放在另一个硬盘驱动器上,那么这可能是个好选择。
有关详细信息,请参阅文档:http://docs.vagrantup.com/v2/other/environmental-variables.html
.box
文件。如其他答案所述,在下载过程中,.box文件存储为:~/.vagrant.d/tmp/boxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
文件名为'box'后跟40字节的十六进制哈希值。例如,在我的系统上,临时文件名为:
~/.vagrant.d/tmp/boxc74a85fe4af3197a744851517c6af4d4959db77f
*.box
扩展名保存,这就解释了为什么上述搜索无法找到它。检索实际的盒子文件有两种方法:
从vagrantcloud.com下载.box文件
vagrantcloud.com
替换域名。所以https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150530.0.1变成了https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1/providers/virtualbox.box。/providers/virtualbox.box
。所以https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1变成了https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1/providers/virtualbox.boxconfig.vm.box_url
指向该URL。或者直接从Vagrant获取.box文件
这需要您修改ruby源代码,以防止Vagrant在成功下载后删除.box文件。
box_add.rb
文件。在我的系统中,它位于/Applications/Vagrant/embedded/gems/gems/vagrant-1.5.2/lib/vagrant/action/builtin/box_add.rb
box_add
函数。在box_add
函数内部,有一个块读取:
ensure # Make sure we delete the temporary file after we add it, # unless we were interrupted, in which case we keep it around # so we can resume the download later. if !@download_interrupted @logger.debug("Deleting temporary box: #{box_url}") begin box_url.delete if box_url rescue Errno::ENOENT # Not a big deal, the temp file may not actually exist end end
vagrant add box <boxname>
添加另一个.box文件。~/.vagrant.d/tmp/
目录下将其保存为boxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
文件。mv boxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX trusty64.box
。对我来说,这个工具非常有用,可以检索.box文件,以便将其托管在本地快速基础设施上,而不是从HashiCorp的Atlas盒子目录或另一个盒子提供者下载。
这实际上应该成为默认的Vagrant功能,因为它具有非常明确的用例。
vagrant package
命令:http://docs.vagrantup.com/v2/cli/package.html。 - Luke Peterson@Luke Peterson:获取.box文件的更简单的方法。
只需访问https://atlas.hashicorp.com/boxes/search,搜索您想要下载的.box文件。注意.box文件的URL,例如:
https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150530.0.1
然后,您可以使用类似于以下的URL来下载这个.box文件:
https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1/providers/virtualbox.box
我已经尝试并成功地下载了我需要的所有.box文件。希望这会有所帮助。
在Windows操作系统下,此处位置为:C:\Users\\{username}\\.vagrant.d\boxes
。我没有在互联网上找到任何相关文档,并且这对我来说并不是很明显。
Mac:
~/.vagrant.d/
Windows:
C:\Users\%userprofile%\.vagrant.d\boxes
为了进行干净的启动,您需要删除VirtualBox/OtherVMprovider中的文件。
sudo find / -name lucid32.box
。 - irrational John*.box
可能会有用?(顺便问一句,扩展名不应该是.vbox
吗?) - irrational Johnvagrant box add foo
的作用。 - Cheeso/Applications/Vagrant/embedded/gems/gems/vagrant-1.5.2/lib/vagrant/action/builtin/box_add.rb
。 - Luke Peterson