Stage 2 Addendum 1: Using Vagrant to make a baseline

Vagrant and the box life cycle


In Stage 2 we build five virtual machines with docker and consul, but it was slow, and we need to make faster changes, for example in Stage 3 will test two options, with new and complex software, and we have time to lose waiting to build the same machine again and again.


We need to make a base for all the others machines, only once to install consul and docker. Then we can build a hierarchical set of base machines for another uses, like swarm servers of other specialized servers, and even build base machines based in another bases.


For build a base machine we need to package a full virtual machine and select this package to create other virtual machines and packages.


In Vagrant this feature is called box, you can build a box from any virtual machine and import it in a repository to be used again in any moment.


We need to know some Vagrant commands and know how to use to manipulate virtual machines and boxes.


Vagrant Box Life cycle

  • Vagrant up MACHINE_NAME

UP command call Vagrant to read the file called "Vagranfile" and execute it. If is called without arguments will raise all the machines configured in the Vagranfile.

  • Vagrant halt MACHINE_NAME

HALT shut running machines, is necessary for build a package of a virtual machine.

  • Vagrant package MACHINE_NAME

PACKAGE build boxes. A box is a virtual machine (stopped) encapsulated to be importable to create other virtual machines.


To make a base machine and package it as a box we can do:

~/base_docker$ vagrant halt
~/base_docker$ vagrant package --output ~/repository/base_docker.box base-docker


  • Vagrant box MACHINE_NAME

BOX let us to manage external boxes and add our own boxes created by the package command. In our case we can add the box with

~/base_docker$ vagrant box add ~/repository/base_docker.box --name elasticmmldap/base_docker --box-version=`date +"%Y%m%d%H%M"`

  • Vagrant destroy MACHINE_NAME

DESTROY do the job opposite to UP, stop and erase all machines or the machine named.

In each stage is possible that we need to destroy all the machines to raise them again in the next stage.

For example after stage 1 and stage 2, all the machines must be cleared.

~/elasticmmldap_stage1$ vagrant destroy -f

All the process in only one script:

$ mkdir ~/repository
$ git clone -b base_docker https://github.com/aescanero/elasticmmldap base_docker
$ cd base_docker
~/base_docker$ vagrant up
~/base_docker$ vagrant halt
~/base_docker$ vagrant package --output ~/repository/base_docker.box base-docker
~/base_docker$ vagrant box add ~/repository/base_docker.box --name elasticmmldap/base_docker
~/base_docker$ vagrant destroy


Comments