Vagrant: Box Up and Go!

Sheldon Nunes
Happy Giraffe

--

I recently gave a talk on Vagrant at a Lightning Talk session on OS Virtualisation. The expected talks were all going to be about Docker and Vagrant seemed to be lacking the love and attention it duly deserves.

What it is

Vagrant is a tool enabling developers to create a virtual machine instance with the necessary packages/software that you require to run your project. For example if you were working on a Python project being able to create a VM with a specific version of Python and any dependencies makes setting up and running a breeze!

Setting up

Starting with Vagrant is a quick and easy process. Simply download it for your intended operating system of your host machine and run the installer. You can verify it successfully installed by running command vagrant in your terminal.

You can setup your Vagrant project by navigating to your project directory and running the command vagrant init. This will generate out a VagrantFile.

Now all that is remaining is to add a box (essentially the VM image you are wanting to use). The Vagrant website uses the following example

vagrant box add hashicorp/precise64

There is a whole bunch of boxes you can use that are catalogued on the Vagrant website. You can even create your own as well if needed.

With all of that complete simply replace the config.vm.box line in the VagrantFile with the following.

config.vm.box = "hashicorp/precise64"

Now run vagrant up. This will start the process to creating your Vagrant VM instance. This creates the VM which you can then enter using vagrant ssh.

Vagrant creates turns the project folder into a shared directory allowing developers to code in whatever their preferred IDE/tools and have it accessible on the VM to run.

I recommend continuing the official Vagrant tutorial and getting to the port forwarding stage which will allow you to view a web project (it’s always nice to see things working!)

After all that we have followed a process similar to this diagram below

Why you should use it

Because Vagrant uses VM architecture instead of containers it is considered to have better isolation and guaranteed resources at the hardware level. It supports all major OS platforms and has the ability to be integrated with Configuration Management tools such as Chef, Puppet, etc.

My impression from Vagrant is that it has a lot more focus on developer experience compared to some of it’s competitors. No more “works on my machine” bugs! and really simple commands to get up and running!

--

--