Running the docker client on Mac OS X

Update: Nowadays (2016) docker is easily supported on Mac OS with the docker-tools. Just visit https://docs.docker.com/mac/

The newer versions of docker (currently 0.6.2) no longer have a Makefile to build the current version, so the way to a local docker binary for Mac OS X wasn’t obvious for me. But it ain’t that hard:

$ mkdir tmp
$ export GOPATH=`pwd`/tmp
$ go get -v github.com/dotcloud/docker/docker
# (this may take some time)
$ sudo cp tmp/bin/docker /usr/local/bin/
$ rm -rf tmp

If you now run your new docker command, you should get an error about docker being unable to connect to a socket at /var/run/docker.sock:

$ docker  version
Go version (client): go1.1.1
2013/09/09 15:04:07 dial unix /var/run/docker.sock: no such file or directory

The problem is obvious: you don’t have a local docker daemon running.

I assume you followed the vagrant guide at docker.io and have your VirtualBox VM with docker running. We need to modify this VM a bit, so our local docker client can reach the docker server inside it.

Modify the Vagrantfile and add the following line inside the Vagrant::Config.run block (e.g. before the end in line 44):

config.vm.forward_port 4243, 4243 (My Vagrantfile).

Inside the VM, edit the /etc/init/docker file and add the argument -H tcp://0.0.0.0:4243, so the daemon listens on all network devices.

Now reboot the VM with vagrant reload (in your docker project folder), so both previous changes take effect. In your local shell, alias the docker command to use the network as well: alias docker='docker -H tcp://127.0.0.1:4243/'. You may want to add this line to you .bashrc or something similar. When you now enter docker version you should see something like this (note the server version):

$ docker version
Go version (client): go1.1.1
Server version: 0.6.1
Git commit (server): 5105263
Go version (server): go1.1.2

Done! You are good to go. Have fun with Docker!

!!! A word of warning: This changes allows anyone to send your docker daemon commands and control it! You should make sure the VM is only reachable from your local machine. !!!

(This was also posted on Coderwall.com)