Docker via Homebrew

Docker is a great tool for getting lightweight, isolated Linux environments. It uses technology that doesn’t work natively on Macs. Until now you’ve had to boot into a VM to install and use Docker, but it’s now a little easier than that.

As of Docker 0.8 it can be run on Macs thanks to a specially developed, lightweight VirtualBox VM. There are official instructions for installing Docker on Mac, but with Homebrew and cask it’s even easier.

Follow the instructions on the cask homepage to install it. Cask is an extension to Homebrew for installing Mac binary packages via the command line. Think things like Chrome or Steam. Or VirtualBox. Running Docker on Mac requires VirtualBox so if you don’t have it already:

brew cask install virtualbox

Then install Docker and the helper tool boot2docker:

brew install docker
brew install boot2docker

boot2docker takes care of the VM that Docker runs in. To get things started it needs to download the Docker VM and start a daemon that the docker command line tool will talk to:

boot2docker init
boot2docker up

The docker command line tool should now be able to talk to the daemon and if you run docker version you should see a report for both a server and a client. (Note: When I ran boot2docker up it told me that the default port the daemon uses was already taken. I had to specify a different port via the DOCKER_HOST environment variable, which I now set in my shell configuration.)

If everything has gone well to this point you should now be able to start up a Docker instance. This command will drop you into a bash shell in Ubuntu:

docker run -i -t ubuntu /bin/bash

Use ctrl-D to exit. I find this especially helpful for very quickly getting to a Linux command line from my Mac for testing this or that, like checking what versions of software are installing by apt-get.

Visit the Docker documentation to learn more about what you can do with Docker and how to do it.

Docker via Homebrew

9 thoughts on “Docker via Homebrew

  1. hakucho says:

    Thanks for posting this, it was useful. Note that the `docker` formula is now a dependency of the `boot2docker` formula in homebrew, so if you run `brew install boot2docker`, you will also get docker automatically. Now they just need to make virtualbox a dependency too. :-)

    1. Thanks for the “better”, never heard of Caskroom. But when is it best to use Caskroom instead of a distribution of a packge? Just wondering if you have an opinion.

      1. Thats just the GUI app extension of brew..

        But normally you would use it otherwise:
        brew cask install dockertoolbox

        IMHO, better means here, package management, which means easy updates.
        I have all my GUI programs who are available in brew cask installed it that way, so a brew update and brew upgrade also updates all of my GUI programs like Atom, Komodo Edit, Commander One, Filezilla, MySQL Workbench, Spectacle, Sourcetree, Teamviewer etc. and the said dockertoolbox, which also handles the dependencies, so it installs also virtualbox if not already installed..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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