Skip to content

Instantly share code, notes, and snippets.

@mboersma
Last active May 26, 2017 06:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mboersma/7954708 to your computer and use it in GitHub Desktop.
Save mboersma/7954708 to your computer and use it in GitHub Desktop.
Build Docker on Mac OS X and run it as a client connected to a Linux VM running the docker daemon.

Run Docker client on Mac OS X connected to a Linux VM

Official Mac Docker Binary!

None of this is really necessary now that the Docker team is releasing official Mac OS X binary builds. Please see moby/moby#3337 for details.

You may also wish to check out this convenience wrapper for setting up essentially what I describe below: https://github.com/noplay/docker-osx

Install go 1.2 from golang.org

Use the binary .pkg installer for go 1.2 (or later) from golang.org. If you choose the defaults, it isn't necessary to set the $GOROOT environment variable, and the go binary will be in your $PATH. You may have to start a new Terminal window to see these changes.

$ brew rm --force go  # if you had go installed via homebrew
$ # (download and double-click on the .pkg installer now)
$ brew install mercurial
$ # The next 2 lines probably should go in ~/.bash_profile or the like
$ export GOPATH=$HOME/Projects/gowork  # or wherever
$ export PATH=$PATH:$GOPATH/bin
$ go version
go version go1.2 darwin/amd64

Check out and build Docker

Docker client and server apparently need to agree exactly on a version string or resource, so ensure that you build your Mac OS X docker client and provision your Linux VM docker server from the same local repository checkout.

$ cd $GOPATH
$ go get -v github.com/dotcloud/docker/docker
$ cd src/github.com/dotcloud/docker
$ git checkout v0.7.2
$ CC=clang go install -a

Create the Vagrant VM

Edit the Vagrantfile in the docker repository (your current directory if you have been following along). Add the following line inside the Vagrant::Config.run block (in v0.7.2, at line 101):

  config.vm.forward_port 4243, 4243

Save the vagrantfile and run vagrant up to create a box running the docker daemon. SSH into the box and sudo edit the /etc/init/docker.conf upstart daemon file and add the -H argument, so the last two lines are like this:

        "$DOCKER" -H tcp://0.0.0.0:4243 -d $DOCKER_OPTS
end script

Now restart the docker daemon:

Now log out, then reboot the VM using vagrant reload so the docker port is exported at 4243.

Connect the client and test

Back in Mac OS X... Rather than specify a host argument each time we invoke docker, let's just set an alias in ~/.bash_profile: alias docker='docker -H tcp://127.0.0.1:4243/'

Then run docker version and you should see this:

Go version (client): go1.2
Server version: 0.7.2
Git commit (server): 88df052
Go version (server): go1.2
Last stable version: 0.7.2
@ferrouswheel
Copy link

I run into this problem after running install:

DOCKER_HOST=localhost; ~/.go/bin/docker version
Go version (client): go1.2
2014/01/30 10:54:46 Error :Not Found

I'm using Docker 0.7.6, and it matches the docker daemon.

I also run into this issue with Go 1.2: https://code.google.com/p/go/issues/detail?id=6424

... but can get around it using careful application of sudo and chown.

@ferrouswheel
Copy link

P.S. official version is unfortunately no good because of moby/moby#3683

@ferrouswheel
Copy link

The Docker issue I mentioned now has info on how to build a functional OSX client: moby/moby#3683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment