如何更改Vagrant的“默认”机器名? [英] How to change Vagrant 'default' machine name?
问题描述
在启动流动箱时,默认名称是来自哪里?
$ vagrant up
machine'default'up with'virtualbox'provider ...
有没有办法设置?
我发现多个选项令人困惑,所以我决定测试他们,看看他们做什么。
我使用的是VirtualBox 4.2.16-r86992和Vagrant 1.3.3。
调用 nametest
并运行
vagrant init precise64 http://文件。 vagrantup.com/precise64.box
可生成默认Vagrant文件。然后我打开了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
Vagrant.configure('2')do | config |
config.vm.box =precise64
config.vm.box_url =http://files.vagrantup.com/precise64.box
config.vm.definefoohost do | foohost |
end
end
VirtualBox GUI名称: nametest_foohost_1386347922
注释:如果您明确定义了一个虚拟机,则使用的名称将替换为默认。
li>
-
设置提供程序名称
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
/ code>属性,该名称将成为VirtualBox GUI中显示的整个名称。
-
定义VM-提供程序名称
Vagrant.configure('2')do | config |
config.vm.box =precise64
config.vm.box_url =http://files.vagrantup.com/precise64.box
config.vm.definefoohost do | foohost |
end
config.vm.provider:virtualbox do | vb |
vb.name =barhost
end
end
VirtualBox GUI名称:barhost
注释:如果同时使用这两种方法,
所以就是这样。你有两个方法有两个不同的结果。我想这是一个偏好的问题? (我是Vagrant的新人,所以我不能说最好的做法。)
Where does the name 'default' come from when launching a vagrant box?
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
Is there a way to set this?
解决方案 I found the multiple options confusing, so I decided to test all of them to see exactly what they do.
I'm using VirtualBox 4.2.16-r86992 and Vagrant 1.3.3.
I created a directory called nametest
and ran
vagrant init precise64 http://files.vagrantup.com/precise64.box
to generate a default Vagrantfile. Then I opened the VirtualBox GUI so I could see what names the boxes I create would show up as.
Default Vagrantfile
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
end
VirtualBox GUI Name: "nametest_default_1386347922"
Comments: The name defaults to the format DIRECTORY_default_TIMESTAMP.
Define VM
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.define "foohost" do |foohost|
end
end
VirtualBox GUI Name: "nametest_foohost_1386347922"
Comments: If you explicitly define a VM, the name used replaces the token 'default'.
Set Provider Name
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 Name: "foohost"
Comments: If you set the name
attribute in a provider configuration block, that name will become the entire name displayed in the VirtualBox GUI.
Define VM -and- Set Provider Name
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.define "foohost" do |foohost|
end
config.vm.provider :virtualbox do |vb|
vb.name = "barhost"
end
end
VirtualBox GUI Name: "barhost"
Comments: If you use both methods at the same time, the value assigned to name
in the provider configuration block wins.
So there it is. You have two methods with two different results. I guess it's a matter of preference at this point? (I'm new to Vagrant, so I can't speak to best practices yet.)
这篇关于如何更改Vagrant的“默认”机器名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!