在 Vagrant 文件中添加故障安全框 URL

Add fail safe box URL in Vagrant file

我在 Vagrant 文件中添加了本地框 link 如下

config.vm.box = "ubuntu1404"
config.vm.box_url = "http://localserver/ubuntu_trusty64.box"

我的本地服务器可能无法一直访问。我需要为同一个盒子添加另一个盒子 URL,它应该可以从任何地方访问作为故障安全。如何添加另一个框 url ?

How can I add another box url ?

来自 vagrant documentation

config.vm.box_url - The URL that the configured box can be found at. If config.vm.box is a shorthand to a box in HashiCorp's Atlas then this value doesn't need to be specified. Otherwise, it should point to the proper place where the box can be found if it isn't installed.

This can also be an array of multiple URLs. The URLs will be tried in order. Note that any client certificates, insecure download settings, and so on will apply to all URLs in this list.

The URLs can also be local files by using the file:// scheme. For example: "file:///tmp/test.box".

所以你可以

config.vm.box_url = ["http://localserver/ubuntu_trusty64.box", "http://anotherserver/ubuntu_trusty64.box", "file://somelocationtobox"]

要补充一点:这在您第一次 运行 vagrant up 使用此框时很重要,因为 Vagrant 将下载并安装该框(它将存储在 ~/.vagrant.d/boxes 目录)。 下载后,在许多情况下,即使您销毁了 VM,Vagrant 也不会重新下载该框;你可以阅读 config.vm.box_check_update 了解 Vagrant 将尝试重新下载的情况