本文介绍了使用自定义 Vagrantfile 打包一个基本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 lucid32 盒子的特定 Vagrantfile,它安装了一些非常标准的包(PHP/MySQL/Apache),做一些特定的端口转发等等,我设置了它,从 git 签出一个项目并更改一些服务器配置,我想把这个盒子打包给团队中的其他开发者使用,所以使用命令:

I have a specific Vagrantfile for a lucid32 box that installs some pretty standard packages (PHP/MySQL/Apache), does some specific port forwarding and so on, I set it up, checkout a project from git and change some server configurations, I want to package this box for other developers on the team to use, so I use the command:

vagrant package boxname --output test.box --vagrantfile Vagrantfile

我得到一个 test.box 文件,它在包装中注明它正在添加我的特定 Vagrantfile,然后我运行:

I get a test.box file, it notes in the packaging that it's adding my specific Vagrantfile, then I run:

vagrant box add boxname test.box

它出现在 vagrant box list 中就好了,现在当我创建一些测试目录,然后执行 vagrant init boxnamevagrant up然后它使用结帐中的文件和所有内容提供该框,但设置正确的端口转发,并且实际上根本没有使用我打包的 Vagrantfile,而是在该目录中生成了一个新的默认文件.

It appears in vagrant box list just fine, now when I create some test directory, and do vagrant init boxname followed by vagrant upand then it provisions that box with the files from the checkout and everything, but does not setup the proper port forwarding,and is in fact not using my Vagrantfile I packaged it with at all, but generated a new default one in that directory.

我注意到在 ~/.vagrant.d/boxes/boxname 中有默认的 Vagrantfile,以及我打包在 includes/_Vagrantfile 中的那个

I noticed in ~/.vagrant.d/boxes/boxname it has the default Vagrantfile, along with the one I packaged in includes/_Vagrantfile

有什么方法可以让我在执行 vagrant init boxname 时生成特定的 Vagrantfile?

Is there any way I can get the specific Vagrantfile to be the one generated when I do vagrant init boxname?

推荐答案

这实际上都按预期工作.Vagrant 在加载时会加载多个 Vagrantfiles(不仅仅是来自 vagrant init 的那个),和一个盒子一起打包的 Vagrantfile 就是其中之一.有关更多信息,请在此处阅读Vagrantfile 加载顺序":https://www.vagrantup.com/docs/vagrantfile/#load-order-and-merging

This is actually all working as intended. Vagrant loads multiple Vagrantfiles (not just the one from vagrant init) when loading up, and the Vagrantfile packaged with a box is one of those. For more information, read about the "Vagrantfile Load Order" here: https://www.vagrantup.com/docs/vagrantfile/#load-order-and-merging

简而言之:Vagrant 按特定顺序加载多个 Vagrantfile,并合并它们的配置.盒子 Vagrantfile 在根 Vagrantfile(来自 vagrant init 的那个)之前作为这个过程的一部分被加载.

In a nutshell: Vagrant loads multiple Vagrantfiles in a specific order, and merges their configurations. The box Vagrantfile is loaded as part of this process prior to the root Vagrantfile (the one from vagrant init).

目前没有办法制作使用 vagrant init 生成的骨架 Vagrantfile.

There is no way currently to make a skeleton Vagrantfile that is generated with vagrant init.

您在打包的 Vagrantfile 中放置的配置,例如端口转发,应该正确加载,因为在合并配置时,它应该只附加所有端口转发.

The configuration you put in the packaged Vagrantfile, such as port forwards, should be loading in properly, since when merging configurations, it should just append all the port forwards.

如果这没有发生,你应该报告一个错误!但是为了 SO 的答案,这就是事情应该如何表现.

If this isn't happening, you should report a bug! But for the sake of a SO answer, this is how things are supposed to behave.

这篇关于使用自定义 Vagrantfile 打包一个基本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 17:51