Vagrant
Vagrant helps you to create and manage a virtualized environment.
Installing
Vagrant requires a previous VirtualBox installation.
Download and install Vagrant from: https://www.vagrantup.com/
Commands
vagrant init: Initialize a Vagranfile.vagrant up: Create a virtual machine from Vagratfile.vagrant up --debug: verbose debug optionvagrant ssh: SSH conection to the current virtual machine.vagrant suspend: suspends the current machine (save state)vagrant resume: resume a suspended vagrant machinevagrant halt: shutdown a virtual machinevagrant destroy: stops and delete the vagrant machinevagrant provision: force the provisioners to be run again a virtual machine. Useful for updating the configuration of existing virtual machines.
Vagrant first steps tutorial
Instructions to create a ubuntu virtual machine from scratch.
- Create a directory for your virtual machine configuration:
mkdir my-vm - Move to the new directory:
cd my-vm - Initialize a configuration file:
vagrant init - Edit the new file 'Vagrantfile' deletig all commented lines:
nano Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "base"
end
- Launch a new virtual machine based on the current Vagrantfile:
vagrant up
The proccess will fail due to a bad configuration. There's no "base" box.
- Edit the Vagrantfile. Change "base" for another valid box name (view boxes on Vagrant Cloud)
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
end
- Launch the new virtual machine again:
vagrant up - Connect to the new virtual machine:
vagrant ssh - Exit from the new virtual machine:
exit - Shutdown the new vm:
vagrant halt - Delete the vm:
vagrant destroy