Skip to main content

@Vagrantup from scratch - Day #1

A friend got himself a brand new Lenovo ThinkPad. He wanted to create new virtual machines to play with Puppet, Docker and other tools. Here you go buddy. We will start with some best practices.

Best practices

I recommend these best practices so that it will be easy to find all virtual machines you create, save disk space and you'll be ready to go in an instant when you want to do something new. 

Workspaces

Keep all your vagrant workspaces in one folder. I keep mine in c:\workspaces\vagrantWorkspaces because I have workspaces for Eclipse, Visual Studio and others. Surely do back up this folder frequently.

Tracking

Maintain an excel file or Google Spreadsheet file with a list of all virtual machines you create to reuse and wish to keep.

Packaging

If you wish to package any of the virtual machines as .box files, store them outside the workspace folders. Keep your workspace small so it is easy and quick to backup.

Naming convention

Choose a naming convention, so you will know which box has which operating system and primary tool etc.

For example, I have a 'JenkinsTomactTrusty64' virtual machine which tells me that this virtual machine has:
  1. Ubuntu Trusty64 operating system 
  2. With Jenkins running on a Tomcat server. 

Minimum number of apps per virtual machine

As much as possible, run the minimum number of services or applications on each virtual machine. If you have a need for more applications to be running and communicating between them, create separate virtual machines and connect them by using the port forwarding features in VirtualBox. For example, if you need a web site that connects to a database, create two separate virtual machines, one for the web server and the other for the database. 

This way, when you need to host another application that needs the same database server, you have a choice of creating a copy of the existing database virtual machine or you could choose to use the same database virtual machine to host the data for this other app. This also allows the virual machines to be small, portable and reusable. 

Create base boxes

This is a slightly advanced topic, but I will mention it here as this is about best practices. Vagrant allows you to create reusable base boxes. Basically, you can create a virtual machine, update it, add your app or service to it and then package it as a template so that you can create new virtual machines using this template as the base. This is such a great feature. It allows me to fire up instantly any new virtual machine with most of the provisioning already setup. In most cases, it takes less than 60 seconds for the virtual machine to be up and running when you have base boxes on your host.

Getting started

I am sure the above stuff was boring. Let us get into the good stuff now. We will install the tools required and fire up a new virtual machine.

Step 1

Install the following in the order listed.
  1. VirtualBox
  2. Vagrant
  3. GitBash (Optional, but good to have if your host OS is Windows)

Step 2

Start your first vagrant box.

  1. Create a new folder inside your vagrant workspace folder. For now, go with a folder named 'init'.
  2. Open cmd or git bash and change directory to this init folder.
  3. Execute the following commands.

vagrant init hashicorp/precise64 // This command creates a new Vagrantfile in the init folder. hashicorp/precise64 is a Ubuntu Precise64 VM hosted at Hashicorp (parent of Vagrant). Read through it later. Lots of interesting features are listed in the comments of this document.

vagrant up // This command downloads a basebox from Vagrantup.com, creates a Virtualbox VM and starts it up.

Step 3

When the command prompt is available, execute the following command to SSH into the new virtual machine.

vagrant ssh

You could also open the VirtualBox application and see the new virtual machine in the list.


On the next post, we will talk about downloading virtual machines with specific operating systems and creating your own base box from scratch. Have fun!


Popular posts from this blog

Create #VirtualPrivateCloud, NAT Instance and NAT Gateways on @AWSCloud

Create a Virtual Private Cloud, NAT instance and the new NAT Gatweay ... and making it all work. This is a YouTube playlist of three videos.

A @trello board to get kids excited

My 8 year old just started his summer break. He did so well in school and I am proud of him. He skipped second grade, got into the gold honor roll in every quarter and got a medal for doing that. Last night, I promised to install a new app for him on his iPad mini. I installed Trello and created a board for him while he watched. I showed him how to create cards, add labels to them and move them from To Do, to Doing to Done. I had him create some cards and label them. He could not stop creating cards. I could not convince him to go to bed after that. He created cards for everything he wants to do in the summer and he is not done with creating cards. He even created a card to email a screenshot of his Trello board to his teacher. Later last night, he was still awake in bed when I checked on him. He told me that he wanted to add three more labels - Math, Science and One-on-One. He wanted a label titled 'One-on-one' for tasks that he wants to do with me and he wants one-on-one at

Cheat sheet to create a #VPC and Subnets on @AWSCloud

One of the critical things to remember for working with a AWS VPC is creating and using it. I had hard time remembering how to do it, so, I wrote down a cheat sheet for myself.  If anyone wants to follow along, just navigate to the VPC page on the AWS Console and start with 'Create VPC' button. Please note that this may cost some dollars if you are not on the free tier. If you are on the free tier and make mistakes, it may cost some dollars. In the steps below, we will be creating the following on a new VPC: An internet gateway One public subnet with routes for accessibility from the internet One private subnet without any routes One EC2 web server with Apache installed in it and serving a sample html page - using the public subnet. One EC2 server with the private subnet and security group that allows access to resources running on the public subnet only.  Create VPC Name tag: myVPC CIDR Block: 10.0.0.0/16 Tenancy: default (Must have default. Otherwise, it