Vagrant
Vagrant is an open-source utility created by guys in Hashicorp.
It is a wrapper utility that works on top of Virtual machine solutions like Virtualbox, HyperV, VMware, and also Docker.
Vagrant is an open-source tool that helps us to automate the creation and management of Virtual Machines.
In a nutshell, we can specify the configuration of a virtual machine in a simple configuration file, and Vagrant creates the same Virtual machine using just one simple command. It provides command-line interfaces to automate such tasks.
What is Virtual Machine?
Virtual Machine is a machine that does not exist physically but can be used just like a physical computer. Any task that can be done on a physical machine can also be executed in a virtual machine.
But Virtual Machine is built on top of a physical system, and multiple virtual machines can be created in a single physical computer.
All the virtual machines share the same hardware, but each of them might have a separate operating system.
The physical system that hosts all the virtual machines is called the Host Computer. The medium that separates the Host Computer hardware and the virtual environments is something called Hypervisor, or Hyper-V.

Each Virtual Machine should have its own configuration like operating system, CPUs, RAM, Hard Disk Memory, networking, etc.
Vagrant Architecture

Terminologies Of Vagrant
Vagrant Box
The basic unit of Vagrant setup is Vagrant Box. Just like Docker Image, Vagrant Box is a self-contained image of the Operating System. More specifically, it is a packaged Virtual Machine.
All that is required to do is to download the Vagrant Box and run it. Vagrant creates the VM and development work can be started immediately.
Vagrant File
Vagrant maintains one configuration file, called Vagrantfile, where all configurations of a VM are mentioned. And Vagrant creates the Virtual Machine with the same configuration mentioned in the file.
Even if there is a need to install some software in the VM, one can specify the same in Vagrantfile, and Vagrant downloads and installs the same for us.
Here is an example Vagrantfile,
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
end
Installation
Step 1: Download Vagrant based on your operating system and install it in the system.
Step 2: Verify vagrant installation using command vagrant -v in command prompt.
vagrant -v
Step 3: Download Virtual Box based on your operating system and install it in the system.
Project Setup
Step 1: Create a folder where we want to save all the Vagrant-related files.
Step 2: Open command prompt (for Windows) or Terminal (for Linux) and go to the location of the folder that was created in step 1.
Step 3: Run command vagrant init ubuntu/trusty64, and let the execution complete. it will automatically creates vagrantfile in specified directory.
vagrant init ubuntu/trusty64
Machine Workflow
Go to the same directory and use below commands to create, run and connect our VM.
vagrant up
once it's done you can use ssh command to create a connection to your VM.
vagrant ssh
For stopping our VM machine use this below command.
vagrant halt
Exit from the VM in PowerShell or terminal and run the command vagrant reload to reload the new setting that we added in Vagrantfile.
vagrant reload
For destroying our VM use destroy command to remove all configurations.
vagrant destroy
Last updated