启动a时,名称“default”来自何处 流浪汉 </跨度> 框?
$ 流浪汉 </跨度> 向上使用’virtualbox’提供程序将计算机’默认’打开…
有没有办法设置这个? …
这是我为各个VM分配名称的方式。更改 YOURNAMEHERE 到你想要的名字。
YOURNAMEHERE
Vagrantfile的内容:
Vagrant.configure("2") do |config| # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "precise32" # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. config.vm.box_url = "http://files.vagrantup.com/precise32.box" config.vm.define :YOURNAMEHERE do |t| end end
终端输出:
$ vagrant status Current machine states: YOURNAMEHERE not created (virtualbox)
如果你想改变其他任何东西而不是'default',那么只需将这些额外的行添加到你的Vagrantfile:
config.vm.define "tendo" do |tendo| end
其中“tendo”将是显示的名称而不是默认名称
是的,对于Virtualbox提供商,请执行以下操作:
Vagrant.configure("2") do |config| # ...other options... config.vm.provider "virtualbox" do |p| p.name = "something-else" end end
我发现多个选项令人困惑,所以我决定测试所有这些选项以确切了解它们的作用。
我正在使用VirtualBox 4.2.16-r86992和Vagrant 1.3.3。
我创建了一个名为的目录 nametest 跑了
nametest
vagrant init precise64 http://files.vagrantup.com/precise64.box
生成默认的Vagrantfile。然后我打开了VirtualBox GUI,这样我就可以看到我创建的框会显示的名称。
默认的Vagrantfile
Vagrant.configure('2') do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" end
VirtualBox GUI名称: “nametest_default_1386347922”
评论: 名称默认为DIRECTORY_default_TIMESTAMP格式。
定义VM
Vagrant.configure('2') do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.define "foohost" end
VirtualBox GUI名称: “nametest_foohost_1386347922”
评论: 如果您明确定义了VM,则使用的名称将替换令牌“default”。这就是名字 的 流浪汉 强> 控制台上的输出。简化基于 zook 的(评论者)输入
zook
设置提供商名称
Vagrant.configure('2') do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.provider :virtualbox do |vb| vb.name = "foohost" end end
VirtualBox GUI名称: “foohost”
评论: 如果你设置了 name 属性在提供程序配置块中,该名称将成为VirtualBox GUI中显示的整个名称。
name
的 组合示例: 强> 定义VM - 并设置提供程序名称
Vagrant.configure('2') do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.define "foohost" config.vm.provider :virtualbox do |vb| vb.name = "barhost" end end
VirtualBox GUI名称: “barhost”
评论: 如果同时使用两种方法,则分配给的值 name 在提供程序配置块中获胜。简化基于 zook 的(评论者)输入
组 hostname (奖金)
hostname
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.hostname = "buzbar" end
评论: 这将在VM中设置主机名。这将是输出 hostname VM中的命令,这也是提示中可见的内容 vagrant@<hostname> ,这里看起来像 vagrant@buzbar
vagrant@<hostname>
vagrant@buzbar
Vagrant.configure('2') do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.hostname = "buzbar" config.vm.define "foohost" config.vm.provider :virtualbox do |vb| vb.name = "barhost" end end
就是这样。您现在知道可以设置3种不同的选项以及它们具有的效果。我想这是一个偏好的问题吗? (我是Vagrant的新手,所以我还不能谈论最佳实践。)
我指定名称 的 确定 强> 在 - 的里面 的 VagrantFile 强> 并指定 的 主机名 强> 所以我喜欢在独立于设备操作系统的情况下执行Linux命令时看到我的项目名称。 ✌️
config.vm.define "abc" config.vm.hostname = "abc"
您可以通过更改值来更改vagrant默认计算机名称 config.vm.define 。
config.vm.define
这是使用的简单Vagrantfile getopts的 并允许您动态更改名称:
# -*- mode: ruby -*- require 'getoptlong' opts = GetoptLong.new( [ '--vm-name', GetoptLong::OPTIONAL_ARGUMENT ], ) vm_name = ENV['VM_NAME'] || 'default' begin opts.each do |opt, arg| case opt when '--vm-name' vm_name = arg end end rescue end Vagrant.configure(2) do |config| config.vm.define vm_name config.vm.provider "virtualbox" do |vbox, override| override.vm.box = "ubuntu/wily64" # ... end # ... end
因此,要使用不同的名称,您可以运行例如:
vagrant --vm-name=my_name up --no-provision
注意: --vm-name 参数需要在之前指定 up 命令。
--vm-name
up
要么:
VM_NAME=my_name vagrant up --no-provision
如果有很多人使用你的流浪文件 - 你可能想要 的 动态设置名称 强> 。下面是如何使用您的用户名进行操作的示例 的 主机 强> 作为框和主机名的名称:
require 'etc' vagrant_name = "yourProjectName-" + Etc.getlogin Vagrant.configure("2") do |config| config.vm.box = "ubuntu/xenial64" config.vm.hostname = vagrant_name config.vm.provider "virtualbox" do |v| v.name = vagrant_name end end