Docker on your Mac using Vagrant

The first time I tried docker I used boot2docker without complete knowledge of it. The idea behind boot2docker is really quite clever: since we can’t run docker natively on Mac, we install a bare-bones Linux VM that can run docker, and then we communicate with it using a docker client running on our host.

After some initial tests I started looking for a different solution considering that I already installed Vagrant on my machine.

This guide explain how to use docker on mac using Vagrant with VirtualBox or Parallels as provider without installing boot2docker.


Vagrant installation

$ brew cask install vagrant

Provider installation

Vagrant has the ability to manage different provider such as VirtualBox, Parallels and VMware. By default it uses VirtualBox which is free, other providers need license to run.

If you want to use default provider just install VirtualBox:

$ brew cask install virtualbox

Otherwise if you have already installed Parallels on your machine:

$ vagrant plugin install vagrant-parallels

The Vagrant plugin installer will automatically download and install vagrant-parallels plugin.

Docker installation

$ brew install docker

Build and run your docker VM

Create a new directory, name it docker and create Vagrantfile:

$ mkdir docker
$ cd docker
$ touch Vagrantfile

Now edit your Vagrantfile and add:

Vagrant.require_version ">= 1.6.5"


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "yungsang/boot2docker" "private_network", ip: ENV['BOOT2DOCKER_IP'] || ""

  config.vm.provider "parallels" do |v, override| = "parallels/boot2docker" "private_network", type: "dhcp"

  # Fix busybox/udhcpc issue
  config.vm.provision :shell do |s|
    s.inline = <<-EOT
      if ! grep -qs ^nameserver /etc/resolv.conf; then
        sudo /sbin/udhcpc
      cat /etc/resolv.conf

  # Adjust datetime after suspend and resume
  config.vm.provision :shell do |s|
    s.inline = <<-EOT
      sudo /usr/local/bin/ntpclient -s -h

Now you’re able to run your VM:

### VirtualBox
$ vagrant up

### Parallels
$ vagrant up --provider parallels

Finally, you’ll need to set an environment variable called DOCKER_HOST that will tell your Docker client on your host machine the URI for the Docker daemon running on the VM.

$ export DOCKER_HOST="tcp://`vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp"`:2375"

Once you’ve completed all these steps, you should have the Docker client installed and a VM capable of starting Docker containers. To test it out, try the command docker run hello-world from your host:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from hello-world
a8219747be10: Pull complete
91c95931e552: Already exists
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd18681cf5daeb82aab55838d
Status: Downloaded newer image for hello-world:latest
Hello from Docker.

Good Dockering! 😉


In some case you can encounter this error “Error response from daemon: client and server don’t have same version”. To solve this problem install older or newer Docker version on your machine.

$ brew tap homebrew/versions
$ brew install homebrew/versions/docker
$ brew search docker
$ brew install homebrew/versions/docker150

Leave a Reply

Please Login to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.