Kyl*_*ley 223 configuration virtualbox vagrant vagrantfile
启动流浪盒时,"默认"这个名称来自哪里?
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
Run Code Online (Sandbox Code Playgroud)
有没有办法设置这个?
odi*_*ity 331
我发现多个选项令人困惑,所以我决定测试所有这些选项以确切了解它们的作用.
我正在使用VirtualBox 4.2.16-r86992和Vagrant 1.3.3.
我创建了一个名为nametest
and ran 的目录
vagrant init precise64 http://files.vagrantup.com/precise64.box
Run Code Online (Sandbox Code Playgroud)
生成默认的Vagrantfile.然后我打开了VirtualBox GUI,这样我就可以看到我创建的框会显示的名称.
默认的Vagrantfile
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
end
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
VirtualBox GUI名称: "nametest_foohost_1386347922"
注释: 如果明确定义VM,则使用的名称将替换标记"default".这是控制台上的名称vagrant输出.基于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
Run Code Online (Sandbox Code Playgroud)
VirtualBox GUI名称: "foohost"
注释: 如果name
在提供程序配置块中设置该属性,则该名称将成为VirtualBox GUI中显示的整个名称.
组合示例:定义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
Run Code Online (Sandbox Code Playgroud)
VirtualBox GUI名称: "barhost"
注释: 如果同时使用这两种方法,则name
在提供程序配置块中分配的值将获胜.基于zook
'(评论者)输入简化
套装hostname
(奖金)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.hostname = "buzbar"
end
Run Code Online (Sandbox Code Playgroud)
注释:这将在VM中设置主机名.这将是hostname
VM 中命令的输出,这也是提示中可见的内容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
Run Code Online (Sandbox Code Playgroud)
就是这样.您现在知道可以设置3种不同的选项以及它们具有的效果.我想这是一个偏好的问题吗?(我是Vagrant的新手,所以我还不能谈论最佳实践.)
nik*_*hil 59
这是我为各个VM分配名称的方式.更改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
Run Code Online (Sandbox Code Playgroud)
终端输出:
$ vagrant status
Current machine states:
YOURNAMEHERE not created (virtualbox)
Run Code Online (Sandbox Code Playgroud)
Arb*_*zar 17
如果你想改变其他任何东西而不是'default',那么只需将这些额外的行添加到你的Vagrantfile:
config.vm.define "tendo" do |tendo|
end
Run Code Online (Sandbox Code Playgroud)
其中"tendo"将是显示的名称而不是默认名称
是的,对于Virtualbox提供商,请执行以下操作:
Vagrant.configure("2") do |config|
# ...other options...
config.vm.provider "virtualbox" do |p|
p.name = "something-else"
end
end
Run Code Online (Sandbox Code Playgroud)
我通过在VagrantFile中定义来指定名称,还指定了主机名,因此在独立于设备操作系统执行Linux命令的同时,我喜欢看到项目的名称。??
config.vm.define "abc"
config.vm.hostname = "abc"
Run Code Online (Sandbox Code Playgroud)
您可以通过更改值来更改无业游民的默认计算机名称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
Run Code Online (Sandbox Code Playgroud)
因此,要使用其他名称,可以运行例如:
vagrant --vm-name=my_name up --no-provision
Run Code Online (Sandbox Code Playgroud)
注意:--vm-name
需要在up
命令前指定参数。
要么:
VM_NAME=my_name vagrant up --no-provision
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
112456 次 |
最近记录: |