Over a million developers have joined DZone.

Virtualization Matters: Part 1 — From Virtualbox to Vagrant

In Part 1 of this series, I am going to talk about the basics of Virtualbox and Vagrant. Read on for more informaiton.

· Cloud Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database on AWS. Try it now! Brought to you in partnership with MongoDB.

In Part 1 of this series, I am going to talk about Virtualbox and Vagrant. In Part 2, I will talk about what the differences are between Vagrant and Docker. As development cycles become shorter and shorter and your startup wants to be 10 years ahead today virtualization 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 provide some context... I hope everyone is familiar with VirtualBox, which basically provides a way to run any OS as a guest OS in your host machine (Linux/Windows/Mac) etc.

VirtualBox
Developer’s life in Virtual Box – well it works great, wait till it crashes again...again and again…man, I lost my last 2 days of work—wish I would have committed it sooner.

bang_head

2010: Here Comes Vagrant

Written in Ruby, Vagrant is a scripting engine for VirtualBox. It allows you to set up multiple virtual machines.

But, why would someone want to do that?

Import/use Pre-configured Virtual Machine

$ 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 across every platform.

You can configure your Vagrant VM with a bunch of properties available under:

Provisioning

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! And your boss responds, 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 Puppet. Vagrant Provisioning is very powerful, everything that is repeatable is meant to be automated and that's exactly what you get.

For example, 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 a Nutshell

Vagrant allows you to create/extend and provision a new virtual machine so it's available to the masses.

Vagrant

Next, I want to extend this article with Docker (a lightweight container), the future of application delivery.

docker.png

I have covered the 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!

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.

Topics:
virtualization ,virtualbox ,vagrant

Published at DZone with permission of Hardik Pandya, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}