Vagrant: An easy way to create and run portable Virtual Machines

Suppose you are writing a web application and you quickly need a clean Tomcat container running on Ubuntu to test it. Manually building such a container from scratch will take time. If you have team of developers who quickly need a container to test the software in a standard environment then you can use Vagrant. Using Vagrant, you can create Linux based servers with Tomcat on the fly.

Vagrant can provision virtual machines (VM) using a simple command line tool. You have to define the configuration for VM once in a configuration file. Using this configuration file, anybody in your team can launch a VM on a system. This is very handy when you have a team of developers who would like to have access to consistently configured servers for development and testing.

Vagrant uses VirtualBox to provision the virtual machine. You need to have VirtualBox installed on your system before you can run Vagrant. It also supports providers such as Ansible, VMWare and Puppet.

You can download Vagrant from http://www.vagrantup.com/. It supports OS X, Windows and Linux.

In my experiment, I decided to launch an Ubuntu VM. In three steps, I got a Ubuntu virtual machine up and running on my system:

Step 1: Define the configuration

$ vagrant init hashicorp/precise32

Step 2: Now Run the VM. This will download the VM image known as Vagrant Box from the Vagrant cloud . This happens only first time. So the first time start up of VM will take a little longer.

$ vagrant up

Step 3: Start a SSH session.

$ vagrant ssh

I have opened a shell in my Ubuntu VM which I have just started. I have all the goodness of Linux at my disposal now.

Virtual machines created by Vagrant are typically ephemeral, so if you install new software or create the files on them, they will be lost after VM has been halted. However, there is one directory called /vagrant which maps to the host OS’s file system. Any file created in this directory stays even when the VM has been shutdown.

To configure your VMs, all you need is a single file known as Vagrantfile containing the configuration for one or multiple host setup, which is read when you launch your VM.

To shutdown VM, you should use the following command:

$ vagrant  halt

Now the VM has stopped running.

Vagrant has more features such as providing access to your ephemeral VMs through internet using Vagrant cloud. Provisioning software such as a webserver or a database in your VM is also possible. The simplicity of this tool is impressive and therefore it is worth trying it.

 
16
Kudos
 
16
Kudos

Now read this

Choosing a Commercial R Distribution Over Open Source R

RevR organised a meet-up in San Jose on 2nd June before the Hadoop Summit 2014, which I attended to catch up with what was happening in the commercial R world. This blog covers a subset of topics discussed in the meet up punctuated with... Continue →