Skip to content

Instantly share code, notes, and snippets.

@zaim
Last active January 2, 2016 00:09
Show Gist options
  • Save zaim/8220922 to your computer and use it in GitHub Desktop.
Save zaim/8220922 to your computer and use it in GitHub Desktop.
Guide to running Docker on OS X

Guide to running Docker on OS X

If you're in a hurry

Use docker-osx:

  • Easy to use.
  • But still under heavy development.
  • So need to periodically check for updates and redownload their docker script to get any sweet new features.

If you're a hacker

Basically do what docker-osx above does manually:

  1. Install VirtualBox and Vagrant
  2. Use this prebuilt Docker 0.7.2 box in your Vagrantfile (see example): vagrant-docker-0.7.2-virtualbox.box
  3. vagrant up, then vagrant ssh and build Docker.
  4. Then, still inside the Docker VM, run sudo make cross to compile the cross-platform binaries.
  5. Copy out your built OS X binary to somewhere in your $PATH (e.g. /usr/local/bin)
  6. Alias docker to /usr/local/bin/docker -H=tcp://127.0.0.1:4243 (you may replace the IP with a private Vagrant IP)

If you're a hacker in a hurry

If you don't want to build docker, download a prebuilt Docker 0.7.2 binary here.

If you're totally not in a hurry

Wait for Docker's official OS X binary release (slated for 0.7.3), then just brew install docker :) Track the issue here.

Credits

# -*- mode: ruby -*-
# vi: set ft=ruby :
BOX_NAME = "precise64_docker_0.7.2"
BOX_URL = "http://static.orchardup.com/binaries/vagrant/vagrant-docker-0.7.2-virtualbox.box"
PRIVATE_IP = ENV.fetch("DOCKER_PRIVATE_IP", "192.168.33.10")
SYNCED_FOLDERS = ENV.fetch("DOCKER_SYNCED_FOLDERS", "")
$SCRIPT = <<EOF
export DEBIAN_FRONTEND=noninteractive
apt-get update -q
apt-get install -q -y lxc-docker
echo 'export DOCKER_OPTS="-H unix://var/run/docker.sock -H tcp://0.0.0.0:4243"' > /etc/default/docker
stop docker
start docker
EOF
Vagrant.configure("2") do |config|
config.vm.box = BOX_NAME
config.vm.box_url = BOX_URL
config.vm.network :forwarded_port, :guest => 4243, :host => 4243
config.ssh.forward_agent = true
if !PRIVATE_IP.nil? and PRIVATE_IP.strip() != '' then
config.vm.network :private_network, :ip => PRIVATE_IP
end
if !SYNCED_FOLDERS.nil? and SYNCED_FOLDERS.strip() != '' then
SYNCED_FOLDERS.split(':').each do |pair|
host, guest = pair.split('=')
config.vm.synced_folder host, guest
end
end
config.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--memory', ENV['VM_MEMORY'] || 1024]
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
end
config.vm.provision :shell, :inline => $SCRIPT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment