Getting Started:


Up and Running:

! Command

vagrant init hashicorp/precise64

* Create a fully-functioning Ubuntu 12.04 VM.

! Command

vagrant init bento/ubuntu-16.04

* Create a fully-functioning Ubuntu 16.04 VM.

! Command

vagrant up

* Start a VM.

! Command

vagrant ssh

* SSH into working directory's vagrant VM.

! Command

vagrant destroy

* Terminate a running vagrant VM (see "Teardown" section later for more options).

! Command

* Can completely remove the box file with this command:

vagrant box remove

Project Setup:

! Definition

A Vagrantfile is a file that marks the root directory of project and describes the kind of machine and resources that are needed to run the project as well as what software to install and how to access it.

* Many configuration options are relative to the root directory.

! Command

* Initialize directory:

vagrant init

* Vagrantfile is meant to be committed to version control.


! Definition

A box is a base image of a VM.

* Vagrant uses boxes to quickly clone VMs.

* Specifying the box to use is the next step after creating a new Vagrantfile.

Installing a box:

* The commands in "Up and Running" are the ones used to install a box.

! Command

* Example of adding a box:

vagrant box add hashicorp/precise64

* Stores under a name so it can be re-used by other environments.

? I think init does this already, but I'm not positive.

* Can get boxes from websites or local files.

! Website

Can get (and host) boxes from HashiCorp's Atlas box catalog.

* "Boxes are globally stored for the current user"

? I think by this they mean one Ubuntu box is recycled for all Ubuntu projects for every user, but I'm not sure.

* Projects don't modify the actual base image.

* This means that two projects using the same base image won't conflict.

Using a Box:

* Configure a box by modifying Vagrantfile.

* must match name used in "init" command or "box add" command.

* Can optionally specify version of a box with config.vm.box_version.

* Can optionally specify url.

                Vagrant.configure("2") do |config|
           = "hashicorp/precise64"
                    config.vm.box_version = "1.1.0"
                    config.vm.box_url = ""

Synced Folders:

! /vagrant on the guest machine is shared with the directory containing Vagrantfile on the host machine.


! Feature:

Using automated provisioning, vagrant will automatically install software when the VM is started.

* Installing Apache example:

* Putting this shell script as in the same directory as Vagrantfile:

                    #!/usr/bin/env bash

                    apt-get update
                    apt-get install -y apache2
                    if ! [ -L /var/www ]; then
                        rm -rf /var/www
                        ln -fs /vagrant /var/www

* And editing the Vagrantfile:

                    Vagrant.configure("2") do |config|
               = "hashicorp/precise64"
                        config.vm.provision :shell, path: ""

! Notice the "provision" line, which tells Vagrant what to do to set up the machine.

* In particular, it tells it to run the sh file.

! Command

vagrant reload --provision

* Can reload the already-running vm to use new provisions with:

* Particularly complex setups are probably not best done through provisioning, but with custom Vagrant boxes.


* Going to use networking features to give additional options for accessing guest machine from host machine.

Port forwarding:

! Feature

Port forwarding lets you share ports on guest machine through a port on the host machine.

* So the guest machine can act as a server.

* Add to Vagrantfile configuration: :forwarded_port, guest: 80, host:4567

* Can now access Apache file server from host machine via localhost:4567.

* There are other options, including bridging to an existing network.


! Feature

Vagrant Share lets you share your Vagrant environment.

* I didn't really expect it to do anything different.

* Skipping details of vagrant share; not concerned about it right now.


Ways to discontinue VM running:


! Command

vagrant suspend

* Saves current running state of the machine and stops it.

* Can restart with vagrant up, and will resume where left off.

* Fast.

* Uses up a lot of disk space.

* Will still be listed in VirtualBox list.


! Command

vagrant halt

* Shuts down the VM.

* Can restart with vagrant up.

* Preserves contents to disk.

* Slow.

* Will still be listed in VirtualBox list.


! Command

vagrant destroy

* Completely removes the VM from the system-- Nothing left on disk.

* Can restart with vagrant up, but it will take longer to restart everything because it needs to be reprovisioned.

* Will no longer be listed in VirtualBox list.

! Not going beyond "Getting Started" *yet*, because think this may be enough to figure out everything else through Google. May go further in the future.

Setting static, bridged ip:

* Put this into Vagrantfile: "private_network", ip: ""