I can\'t figure out a good way to set up a development environment on OS X using Docker and Boot2Docker. The problem I\'m hitting is how to manage the source
I feel you! I think I've tried pretty much everything you tried and unfortunately it was still slow. Then I came across this comment https://github.com/boot2docker/boot2docker/issues/64#issuecomment-70689254 that suggests using Vagrant and Parallels and instead of Virtualbox. This allowed me to use nfs and I did indeed saw a big performance boost for my project (Drupal).
Here's the Vagrant file. All you need to do is install vagrant, copy this in a file called Vagrantfile and put it in some folder. Go to that folder and just do a vagrant up
instead of your normal boot2docker up.
Vagrant.configure(2) do |config|
config.vm.box = "parallels/boot2docker"
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.synced_folder(
"/Users/dicix/work/www", "/vagrant",
type: 'nfs',
nfs_udp: true,
mount_options: %w[actimeo=2],
bsd__nfs_options: %w[alldirs maproot=root:wheel]
)
end
This method is the latest (Sep 2015) and easiest way to get Docker setup on Mac: link here:
You install Docker using Docker Toolbox link to instructions here:
It is a complete Docker setup package, that includes the following Docker tools:
Docker Machine for running the docker-machine binary
Docker Engine for running the docker binary
Docker Compose for running the docker-compose binary
Kitematic, the Docker GUI a shell preconfigured for a Docker command-line environment
Oracle VM VirtualBox
Docker Unison works like a charm! https://github.com/leighmcculloch/docker-unison
Bidirectional Sync with a very good performance!
Update: Now that docker for mac is in beta with non-hack functionality, going that route may be a lot more reasonable for local development without a essay's worth of hacks and workarounds.
Don't. I know that's not the answer you are probably hoping for, but take an honest evaluation of the cost/benefit of trying to get local source code + dockerized execution vs just doing local development on OSX.
At some point all the issues, setup effort, and operational pain points MAY be resolved well enough, but as of right now my take on this is it's a net loss.
Issue #1: Mounted volumes on Virtual Box (which use vboxfs) are extremely slow
Wait a while and this will almost certainly improve.
Issue #2: File watching is broken
I'm not sure a fix for this is in the near future. If this type of functionality is key to your development workflow, I would consider this a dealbreaker. It's not worth a major R&D effort when compared to just using rbenv/bundler to manage your jekyll/ruby installs and running them locally on OSX like folks have been doing successfully for the past decade+.
Just like "the cloud" has zero involvement in my local development setup, at the moment, docker is a win for testing/staging/deployment and for running databases and other third party components, but the applications I'm actually coding get run straight on OSX.
Getting docker to work as a development tool is possible. But its going to hurt. I've documented the process here :
http://harmingcola.blogspot.com/2015/05/how-to-setup-docker-as-development-tool.html
I've decided to add my own answer with the best solution I've found so far. I'll update this if I find better options.
The best solution I've found for setting up a productive development environment with Docker on OS X is: Boot2Docker + Rsync. With rsync, build times in a Docker container are on par with running the build directly on OSX! Moreover, the file watcher code does not need polling (inotify
works since rsync uses normal folders), so hot reload is almost as fast.
There are two ways to set it up: an automated install and a manual install.
I've packaged all the steps for setting up Boot2Docker with Rsync into an open source project called docker-osx-dev. The code is a bit rough, but I've been successfully using it for several weeks to easily switch between 3 projects with 3 different tech stacks. Try it out, report bugs, and submit some PRs! Also, see my blog post, A productive development environment with Docker on OS X for more info.
brew install boot2docker
.boot2docker init && boot2docker start --vbox-share=disable
.boot2docker shellinit
and copy the environment variables it prints out into your ~/.bash_profile
file.boot2docker ssh "tce-load -wi rsync"
./foo/bar
folder from OS X, you need to create /foo/bar
on the Boot2Docker VM: boot2docker ssh "mkdir -p /foo/bar && chown -R docker /foo/bar"
.rsync --archive --rsh="ssh -i $HOME/.ssh/id_boot2docker -o StrictHostKeyChecking=no" /foo/bar docker@dockerhost:/foo
. Check the rsync docs for various settings you may want to enable, such as using --exclude .git
to exclude the .git
folder when syncing.brew install fswatch
) piped into rsync.docker run
to fire up your Docker container and use the -v
flag to mount the folder you're syncing: docker run -v /foo/bar:/src some-docker-image
.inotify
), and the build should run fast because all the files are "local" to the container.boot2docker ip
command to find out what IP it's on.