Virtulization

Virtualization Matters: Part 1: From VirtualBox to Vagrant to Docker


In Part 1 of this series I am going to talk about Virtualbox and Vagrant, In Part 2 will talk about what are the differences between Vagrant and Docker. As development cycles become shorter and shorter and your startup wants to be 10 years ahead today virtulization affects us all. In Part-3 I want to build and test Spark Application on Docker, stay tuned!!!

Back in 2007 – Rise of Type-2 Hypervisor

Just to set some context, everyone is familiar with VirtualBox, basically running any OS as a guestOS in your host machine (linux/windows/mac) etc.

VirtualBox

 

 

Developer’s life in Virtual Box – well it works great :), wait till it crahses again..again and again…man I lost my last 2 days of work – wish I would have git it soon

 

bang_head

2010: Here comes Vagrant

Written in Ruby, Vagrant is a scripting engine for VirtualBox. So you can setup multiple virtual machines.

But why someone want to do that?

Import/use Pre-configured Virtual Machine

  • For e.g to fire up existing Virtual Machine called hashicorp/precise64 just execute
  • $ vagrant init hashicorp/precise64 (will create vagrantfile)
  • $ vagrant up

After running the above two commands, you will have a fully running virtual              machine in VirtualBox running Ubuntu 12.04 LTS 64-bit.

You can SSH into this machine with vagrant ssh, and when you are done playing around, you can terminate the virtual machine with vagrant destroy.

Configure VM (with .vagrantfile)

There is one Vagrantfile per project, and the Vagrantfile is supposed to be committed to version control. This allows other developers involved in the project to check out the code, run vagrant up, and be on their way. Vagrantfiles are portable to every platform

You can configure your vagrant vm with bunch of properties available under

Provisining

Up to this point you can fire and configure your VM in under 2 mins. But you still have not installed any software in your virtual machine, you say to your boss: I can install those 50 things (cassandra,elasticsearch,spark etc..)needed to develop/run my software – give me a week you say…and your boss say…GIVE ME A BREAK!!!

Vagrant gives you multiple options for provisioning (automate installation) your virtual machine, from simple shell scripts to more complex tools like Chef and Puppets.Vagrant Provisioning is very powerful, everything that is repeatable is meant to be automated and this is exactly what you get

For e.g installing apache – create install-apache.sh and modify your vagrantfile

apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  rm -rf /var/www
  ln -fs /vagrant /var/www
fi

Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision :shell, path: "install-apache.sh" end

 

Vagrant in nutshell

Vagrant allows you to create/extend and provision new virtual machine so its available to masses.

Vagrant

Next I want to extend this article with Docker (a lightweight container); future of application delivery –

docker.png

I have covered very basics of Vagrant. But the point here is automate everything.  We are software developers and we should automate everything as much as possible. Thanks for reading!