This install guide assumes that you have already followed my Vagrant/VirtualBox Guide and have it running successfully.

Open the “Vagrant” file that was created in the directory and add the below content and save:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# 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|
  config.vm.box = "generic/ubuntu1804"
  config.vm.network "forwarded_port", guest: 80, host: 80
  config.vm.provision :shell, path: "bootstrap-ubuntu.sh"

  # Enable provisioning with a shell script. 
  config.vm.provision "shell", inline: <<-SHELL
     echo INSTALLING PACKAGE: tree------------------------------.
     apt-get install tree -y
   SHELL
end

Next, in the same directory ensure a script file named “bootstrap-ubuntu.sh” exists and has:

#!/usr/bin/env bash

echo UPDATE: base machine------------------------------.
apt-get update

#install packages to allow apt to use a repository over HTTPS
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common -y

#Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

#set up the stable repository
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

#install the latest version of Docker Engine and containerd
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y

Having it setup this way allows for some flexibility in configuring the machine. You can run shell commands within the Vagrant file and/or have a bash script run.

Now, from that directory run:

vagrant status

For a clean install run:

vagrant destroy

Then run:

vagrant up

If the image already exists, then you can simply run provision:

vagrant provision  

This should install the latest version of Docker. Log into the machine with:

vagrant ssh

You should now be in the command window for the actual virtual machine. Verify that Docker Engine is installed correctly by running the hello-world image:

sudo docker run hello-world

TO avoid needing “sudo” just switch to root with:

sudo su -

Now, run the following command to pull and run a web server:

docker run -P -d -p 80:80 nginxdemos/hello

Now in a browser go to localhost and you should see an Nginx page:

That is it! You are now ready to get started with Docker! As always, stay inb8a!