Setting up a Docker host on Windows with Vagrant

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

  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.
# config.vm.network “private_network”, ip: “192.168.33.10”
...
# config.vm.provision “shell”, inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL

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

# using a specific IP.
config.vm.network “private_network”, ip: “192.168.10.101”
...
config.vm.provision “shell”, inline: <<-SHELL
wget -qO- https://get.docker.com/ | sh
SHELL

After the edits, the file should look like so:

Vagrantfile with comments removed (custom cpu/memory settings are optional)

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:

192.168.10.101 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!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.