Lab: Using a Vagrant Configuration Script

In this lab you’ll create a new Vagrant box based on the standard box for the class. You will edit the Vagrantfile to include setup instructions. The setup will automatically install the latest version of Docker.

Step 0: Create a New Box Directory

How you do this step will depend on what OS is on your computer. Start by creating a new directory for your customized Vagrant box:

$ mkdir docker-box
$ cd docker-box

Now download the Vagrantfile linked below into the new directory:

Step 1: Create a Customization Script

Vagrant can use complex configuration management software such as Puppet, Chef and Ansible to manage boxes. It can also run a simple shell script when the box starts. Copy and paste this code into a script called in the same directory as your Vagrantfile.

#! /bin/bash 

sudo apt-get update
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
curl -fsSL | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
   "deb [arch=amd64] \
   $(lsb_release -cs) \
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli
sudo usermod -aG docker vagrant

# Install docker-compose 
sudo curl -s -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

The steps in this file are the steps from last week’s class.

Step 2: Update Vagrantfile

Add the following configuration parameter to the Vagrantfile:

  config.vm.provision "shell", path: ""

The configuration parameter must be inside the config clause. Here’s the parameter in context:

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at

  config.vm.provision "shell", path: ""

  # Every Vagrant development environment requires a box. You can search for
  # boxes at = "ubuntu/xenial64"

Step 3: Check the Docker Install

Bring up your new box with vagrant up then login to your Docker box with vagrant ssh. Verify that Docker is installed:

docker run docker/whalesay cowsay "Linux FTW"

Turn In

Turn in a screenshot of the output of whalesay.