Setting up a Docker host on OSX with Vagrant

The instructions on the Docker web page use the Docker Toolbox, but we can also build a Docker host using Vagrant(to provision virtual machines) and VirtualBox (to host virtual machines). Doing this helps us understand how everything fits together.

  1. Install Oracle VirtualBox
  2. Install Vagrant
  3. Open a new terminal 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:

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

Back in the terminal, 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 /etc/hosts and add the following line: dockerbox

In OSX, open a 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.