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
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
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
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
Visit the Docker documentation to learn more about what you can do with Docker and how to do it.
9 thoughts on “Docker via Homebrew”
Great post, much appreciated :)
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. :-)
Thanks for this. Just a heads up, when I ran docker version I got:
FATA Get http:///var/run/docker.sock/v1.16/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
Which was fixed by this answer on SO http://stackoverflow.com/a/27529061/1489062
I ran into that problem too. Thanks for the SO link!
> boot2docker init
WARNING: The ‘boot2docker’ command line interface is officially deprecated.
Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.
Docker Toolbox (https://docker.com/toolbox) is the recommended install method.
> brew install Caskroom/cask/dockertoolbox
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.
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..
Better still, just download the package from here -> https://www.docker.com/toolbox (Mac OS X and Windows)
This way of using Boot2Docker is deprecated – here’s the new instructions: https://docs.docker.com/v1.8/installation/mac/