Vagrant - (Lifetime|Lifecyle) - Command

About

The principal command of Vagrant are defining the lifetime of the virtual machine.

Steps

Init

Init a project directory to be used with vagrant.

cd myVagrantProjectDirectory
vagrant init

It will create a .vagrant directory into the directory project myVagrantProjectDirectory

and add a box. Bv for Ubuntu 64.

vagrant add hashicorp/precise64

Up

vagrant up brings the box VM clone up in the provider (by default VirtualBox)

Vagrant runs the virtual machine by default without a UI to prove that it's running start an ssh session.

From this steps, you want to provision your Vm. See Vagrant - Provision (Code, Software Installation)

Reload

vagrant reload quickly restart the virtual machine, skipping the initial import step.

Tear down

With Vagrant, you suspend, halt, or destroy the guest machine. Each of these options have pros and cons.

Suspend

  1. vagrant suspend will save the current running state of the machine and stop it.
  2. vagrant up will resumed the machine from where you left off.

Cons and pro:

  • The main benefit of this method is that it is super fast, usually taking only 5 to 10 seconds to stop and start your work.
  • The downside is that the virtual machine still eats up your disk space, and requires even more disk space to store all the state of the virtual machine RAM on disk.

Halt

  1. vagrant halt will gracefully shut down the guest operating system and power down the guest machine.
  2. vagrant up to boot the machine again.

Pro and cons:

  • The benefit of this method is that it will cleanly shut down your machine, preserving the contents of disk, and allowing it to be cleanly started again.
  • The downside is that it'll take some extra time to start from a cold boot, and the guest machine still consumes disk space.

Destroy

  1. vagrant destroy will remove all traces of the guest machine from your system. It'll stop the guest machine, power it down, and remove all of the guest hard disks.
  2. vagrant up to restart

Pro and cons:

  • The benefit of this is that no cruft is left on your machine. The disk space and RAM consumed by the guest machine is reclaimed and your host machine is left clean.
  • The downside is that vagrant up to get working again will take some extra time since it has to reimport the machine and re-provision it.

The vagrant destroy command does not actually remove the downloaded box file. To remove it, see vagrant box remove


Powered by ComboStrap