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?
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?
If you want to change anything else instead of 'default', then just add these additional lines to your Vagrantfile:
Change the basebox name, when using "vagrant status"
Where "tendo" will be the name that will appear instead of default
In case there are many people using your vagrant file - you might want to set name dynamically. Below is the example how to do it using username from your HOST machine as the name of the box and hostname:
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 ranto 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
VirtualBox GUI Name: "nametest_default_1386347922"
Comments: The name defaults to the format DIRECTORY_default_TIMESTAMP.
Define VM
VirtualBox GUI Name: "nametest_foohost_1386347922"
Comments: If you explicitly define a VM, the name used replaces the token 'default'. This is the name vagrant outputs on the console. Simplifying based on
zook
's (commenter) inputSet Provider Name
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.Combined Example: Define VM -and- Set Provider Name
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. Simplifying based onzook
's (commenter) inputSet
hostname
(BONUS)Comments: This sets the hostname inside the VM. This would be the output of
hostname
command in the VM and also this is what's visible in the prompt likevagrant@<hostname>
, here it will look likevagrant@buzbar
Final Code
So there it is. You now know 3 different options you can set and the effects they have. 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.)
Yes, for Virtualbox provider do something like this:
I specify the name by defining inside the VagrantFile and also specify the hostname so i enjoy seeing the name of my project while executing Linux commands independently from my device's OS. ✌️
You can change vagrant default machine name by changing value of
config.vm.define
.Here is the simple Vagrantfile which uses getopts and allows you to change the name dynamically:
So to use different name, you can run for example:
Note: The
--vm-name
parameter needs to be specified beforeup
command.or: