I have been using Vagrant over the past three years for development. It has probably been one of the most used, productivity boosting tools in my toolbox.
What Vagrant provides out of the box is an open source command-line interface to VirtualBox with the a consistent and reproducible workflow from development to deployment. Although VirtualBox is an open source product, I prefer VMware Fusion for my development, as I have found it to be more performant and reliable. A plugin is available from HashiCorp that provides VMware integration, which in my opinion is a worthy investment. In addition to VMware integration, Vagrant also provides support for AWS, Rackspace, and Digital Ocean.
To create a new Ubuntu VM using Vagrant, run the following command:
$ vagrant init ubuntu/trusty64
This command produces a file named Vagrantfile
in the current working directory. This file is the manifest for the VM. It allows developers to configure VM settings (i.e. CPU, Memory, Networking, etc). Additionally, the Vagrantfile allows developers to provision software on the VM using provisioning tools such as: Ansible, Puppet, and Chef, or shell. I find myself more often using the shell provisioner to quickly get up and running.
Without modifying the default Vagrantfile
, we can start the VM by running:
$ vagrant up
Bringing machine 'default' up with 'vmware_fusion' provider...
...
This command first checks to see if a copy of the Vagrant box ubuntu/trusty64
is cached locally. A Vagrant box is a prepackaged virtual machine with a base operating system installed as well as any additional software required to provision the VM (e.g. Ruby, SSH keys, etc).
Once the box is downloaded, the VM comes online, immediately followed by any user-defined software provisioning steps.
To check the status of the VM, execute:
$ vagrant status
Current machine states:
default running (vmware_fusion)
To access the drop into the command line shell of the VM, execute:
$ vagrant ssh
Last login: Sat May 23 16:55:51 2014 from 172.16.230.1
[vagrant@localhost ~]$
By default, the current working directory is mounted as /vagrant
in the VM. This is a convenient setup when iterating through a development cycle. This allows developers to quickly develop and test their code on their laptop regardless of the host operating system without copying files across the network.
To shutdown the VM, execute:
$ vagrant halt
To cleanup the files created and restore local disk space, execute:
$ vagrant destroy
NOTE: All data on the VM will be lost.