Skip to content

Instantly share code, notes, and snippets.

@blalor
Created July 18, 2014 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blalor/c6719dd854aa8bbb2a92 to your computer and use it in GitHub Desktop.
Save blalor/c6719dd854aa8bbb2a92 to your computer and use it in GitHub Desktop.
OS X Docker dev env with Vagrant that doesn't suck entirely

This'll suffice until boot2docker get their shit together and give me VirtualBox shared folder support.

On OS X, just export DOCKER_HOST=tcp://172.28.128.3:4243 and off you go. All exposed ports can be accessed via 172.28.128.3 (assuming that's the IP you get from VirtualBox).

Your entire home directory is mounted under the same path, so from OS X you can do docker run -i -t -v $HOME/devel/some-project:/srv/some-project image /bin/bash and the volume will be mounted as you'd expect. With a caveat: filesystem notifications (inotify and friends) don't get passed along.

#!/bin/bash
if [ ! -e /var/run/docker_provisioned ]; then
mkfs.ext4 -F -m 0 -L var-lib-docker /dev/sdb
mkdir /var/lib/docker
echo "LABEL=var-lib-docker /var/lib/docker ext4 defaults 0 0" >> /etc/fstab
mount /var/lib/docker
yum install -y docker-io
usermod -a -G docker vagrant
sed -i -e '/other_args/ s#^.*$#other_args="-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock"#g' /etc/sysconfig/docker
chkconfig docker on
service docker start
date > /var/run/docker_provisioned
fi
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure("2") do |config|
config.vm.box = "…"
config.vm.box_url = "…/#{config.vm.box}.box"
config.vm.network(:private_network, type: :dhcp)
config.vm.synced_folder(ENV["HOME"], ENV["HOME"])
config.ssh.forward_agent = true
config.vm.provider :virtualbox do |vb|
file_to_disk = File.dirname(__FILE__) + "/tmp/large_disk.vdi"
unless File.exist?(file_to_disk)
vb.customize ["createhd", "--filename", file_to_disk, "--size", 20 * 1024]
end
# if ARGV[0] == "up"
# vb.customize ["storageattach", :id, "--storagectl", "IDE Controller", "--port", 1, "--device", 0, "--type", "hdd", "--medium", file_to_disk]
# end
vb.memory = 1024
end
config.vm.provision "shell", path: "provision.sh"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment