Setting up a Docker host on Windows with Vagrant

Setting up a Docker host on Windows with Vagrant

Today, we’ll provision a Docker host together using Vagrant and Virtualbox on Windows and add a local DNS entry.

  1. Install Babun
  2. Install VirtualBox (this guide uses 5.0.18)
  3. Install Vagrant
  4. Open a new Babun shell window and create a directory for our vagrant box:
cd ~ && mkdir -p vagrant/trusty64 && cd vagrant/trusty64

Download the Vagrantfile for ubuntu (trusty 64-bit)

vagrant init ubuntu/trusty64

The Vagrantfile contains instructions for how Vagrant should build your virtual machine. Open the Vagrantfile with your text editor of choice and find the following sections:

# using a specific IP.
# “private_network”, ip: “”
# config.vm.provision “shell”, inline: <<-SHELL
#   sudo apt-get update
#   sudo apt-get install -y apache2

Modify it so that Vagrant assigns the IP address “” and installs Docker for us:

# using a specific IP. “private_network”, ip: “”
config.vm.provision “shell”, inline: <<-SHELL
  wget -qO- | sh

After the edits, the file should look like so:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config| = "ubuntu/trusty64" "private_network", ip: ""
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 2048
    vb.cpus = 2
  config.vm.provision "shell", inline: <<-SHELL
    wget -qO- | sh

Back in the Babun shell window, we can bring the virtual machine online by running:

vagrant up

Once the Vagrant box is ready, ssh to it:

vagrant ssh

Now we can start running docker images!

sudo docker run -d -p 80:80 nginx

Remember that IP address we set earlier? Now we can alias it in our hosts file so that it’s easier to remember. Open c:\windows\system32\drivers\etc\hosts (make sure to run your editor as administrator) and add the following line: dockerbox

Save your changes to the hosts file, open your browser, and navigate to http://dockerbox and you should see the nginx welcome page.

Congratulations, you just created a local docker host and deployed nginx!