Last Updated: February 25, 2016
·
24.19K
· zeisss

Running docker as a client on Mac OS X

EDIT: Homebrew now contains docker. Just brew install docker away .... You may still need/want to forwards ports and stuff like that.


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</code> command, you should get an error about docker being unable to connect to a socket at /var/run/docker.sock</code>:

$ 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 <a title="Docker Installation Guide using Vagrant" href="http://docs.docker.io/en/latest/installation/vagrant/" target="_blank">docker.io</a> 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.

  1. Modify the Vagrantfile</code> and add the following line inside the Vagrant::Config.run</code> block (e.g. before the end in <a href="https://github.com/dotcloud/docker/blob/master/Vagrantfile#L44" target="new">line 44</a>): config.vm.forwardport 4243, 4243</code> (My Vagrantfile).

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

  3. Now reboot the VM with vagrant reload (in your docker project folder), so both previous changes take effect.

  4. 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!

<b>!!! 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. !!!</b>

8 Responses
Add your response

Btw, if you want to make all the ports that docker usually assigns to the containers available on your local machine, you can pass an environment variable to Vagrant:

$ FORWARD_DOCKER_PORTS=1 vagrant reload
over 1 year ago ·

Just in case anyone else runs into this,
when you're building the docker client on the mac, make sure you checkout the same release tag in the docker source as is built on the VM.

If they aren't the same version, they likely won't work.

cd $GOPATH/src/github.com/dotcloud/docker
git checkout v0.6.3
go install

Should work as if the version of docker installed on the vm is 0.6.3.

over 1 year ago ·

Saving those of you who are using CoreOS in Vagrant some minutes -- change the docker daemon arguments as follows:

# mount -o remount,rw /
# vim /usr/lib/systemd/system/docker.service
# systemctl daemon-reload
# systemctl restart docker
over 1 year ago ·

@srenatus: That is not a longterm solution, as the update process will overwrite your changes at some point.

Afaik the intended solution is create a new docker-service-config with the needed changes and disable the default docker service.

over 1 year ago ·

@zeisss: indeed, thanks for pointing that out.... I'm still trying to figure out how to properly manage a "production" deployment of CoreOS servers... for example how to populate the running instances' systemds with updated/additional service definitions

over 1 year ago ·

I had a lot of trouble getting Docker to build from Go built in homebrew. It solved it with the information in this issue:

https://github.com/dotcloud/docker/issues/2665

Essentially, when installing Go from homebrew, you need to use the following options:

brew install go --devel --cross-compile-common --with-cgo

over 1 year ago ·

I would be necessary use the mercurial client to install some go package dependencies like sqlite3. Just installing the mercurial with "brew install hg" before effectively install the docker with the go get command works well for me. I installed the 0.7.1 version (git head).

over 1 year ago ·

You don't need an alias. Docker supports now DOCKER_HOST env variable:
https://github.com/dotcloud/docker/pull/3303

over 1 year ago ·