Intro
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 code so that:
- I can modify the code on OS X using the tools (text editor, IDE, git, etc) I already have installed.
- Those modifications are reflected in the Docker container so if I re-run tests or refresh a webpage, I can see my changes immediately.
In theory, this should be easy to do by mounting my source code as a volume:
docker run -it -v /path/to/my/source/code:/src some-docker-image
Unfortunately, this has two major issues that make it completely unusable on OS X:
Issue #1: Mounted volumes on VirtualBox (which use vboxsf) are extremely slow
For example, here is how long it takes Jekyll to compile my homepage if the source code is part of the Docker image:
> docker run -it brikis98/yevgeniy-brikman-homepage:v1 bash
root@7aaea30d98a1:/src# time bundle exec jekyll build
[...]
real 0m7.879s
user 0m7.360s
sys 0m0.600s
Here is the exact same Docker image, except this time, I mount the source code from OS X:
> docker run -it -v $(pwd):/src brikis98/yevgeniy-brikman-homepage:v1 bash
root@1521b0b4ce6a:/src# time bundle exec jekyll build
[...]
real 1m14.701s
user 0m9.450s
sys 0m3.410s
Issue #2: File watching is broken
The default watch mechanisms in SBT, Jekyll, and grunt use technologies such as inotify, which do not work if they are running in a Docker container and the changes are made in OS X to a mounted folder.
Workarounds I tried
I searched for solutions (including all the ones on SO) and tried out a few of them, but have not found a successful one:
- I switched Boot2Docker to use NFS, but it was just as slow.
- I tried Vagrant + NFS, and that was also just as slow.
- I tried a Samba mount, but the folder always showed up empty in the Docker container.
- I tried to use the Unison file system, which worked briefly to sync files, but then kept showing connection errors.
- I enabled polling in Jekyll, but that significantly increased the delay until my changes were picked up.
- I tried Dinghy, a "faster, friendlier Docker on OS X with Vagrant" and got some improvement. Instead of Jekyll compilation being 10-15x slower, it was 2-3x slower. That's better, but still not quite usable.
Has anyone found a solution that actually works and allows you to productively develop code with Docker and OS X?
Update: a solution at last!
I have finally found a solution that seems productive using Boot2Docker + rsync. I've captured the details on how to set this up in my own answer as well as an open-source project called docker-osx-dev.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…